Lil'DexT3r
Lil'DexT3r

Reputation: 47

Display current Folder permission by a batch script

I want my script to fetch the permission details of a particular folder.

Currently, the script i have isn't much user friendly.

icacls %1%

gives a result like this

*NT Authority\System: (I) (OI) (CI) (F)

Administrators: (I) (OI) (CI) (F)

User1: (I) (OI) (CI) (F)*

Is there a way that would enable the script to give result something like this:

The input folder is READ-ONLY (based on what the current permission is of that folder)

This can be possible by in power shell i suppose, but i want it in batch script or Vb script.

Upvotes: 1

Views: 69

Answers (1)

SachaDee
SachaDee

Reputation: 9545

Something like that :

@Echo off&cls
set "$Folder=%cd%"

for /f "tokens=3 delims=:" %%a in ('icacls "%$Folder%" ^| find /i "Authority"') do (
  echo %%a | find "(F)" >nul && echo FULL PERMISSION
  echo %%a | find "(N)" >nul && echo ZERO PERMISSION
  echo %%a | find "(M)" >nul && echo MODIFYING PERMISSION
  echo %%a | find "(RX)" >nul && echo READ^&RUN PERMISSION
  echo %%a | find "(R)" >nul && echo READ ONLY PERMISSION
  echo %%a | find "(W)" >nul && echo WRITE PERMISSION
  echo %%a | find "(D)" >nul && echo DELETE PERMISSION)
  pause

Upvotes: 1

Related Questions