JSI Tip 9901. How can I enumerate the folder permissions on a drive or folder in CSV format?

Using Xcacls.vbs, I have scripted TreePerm.bat to enumerate the permission of a drive or folder tree, using CSV format.

The syntax for using TreePerm.bat is:

TreePerm DriveOrFolder

Where DriveOrFolder is the drive or folder that you wish to fully enumerate, like C: or "C:\Documents and Settings".

The output is displayed on the console, but you can redirect it to a file.

Each line of output contains:

"Full Path to drive or folder","Type","User","Permission","Inheritance"

but any , in the data has been removed and any ( ) characters have been replaced with \[ \] characters.

TreePerm.bat contains:

@echo off
if \{%1\}==\{\} @echo Syntax: TreePerm DriveOrFolder&goto :EOF
if not exist %1 @echo Syntax: TreePerm %1 does NOT exist.&goto :EOF
set obj=%1
set XCACLS=""
for /f "Tokens=*" %%F in ('@echo XCACLS.VBS') do (
 If "%%~dp$PATH:F" NEQ "" set XCACLS="%%~dp$PATH:F%%~F"
if %XCACLS% EQU "" @echo Syntax: TreePerm - XCACLS NOT in PATH&endlocal&goto :EOF 
for /f "Skip=2 Tokens=*" %%a in ('cscript //nologo %XCACLS% %obj% /T /S^|find "\"') do (
 set line=%%a
 call :parse
goto :EOF
if "%line:~0,10%" EQU "Directory:" set fPath="%line:~11%"&goto :EOF
if "%line:~0,6%" EQU "Owner:" set fPath=""&goto :EOF
set type="%line:~0,7%"
set type=%type: "="%
set Usr="%line:~9,23%"
set Usr=%Usr:  =%
set Usr=%Usr: "="%
set Perm="%line:~33,22%"
set Perm=%Perm:  =%
set Perm=%Perm: "="%
set Perm=%Perm:(=\[%
set Perm=%Perm:)=\]%
set Perm=%Perm:,=%
set Inherit="%line:~55%"
set Inherit=%Inherit:  =%
set Inherit=%Inherit: "="%
set Inherit=%Inherit:,=%
@echo %fPath%,%type%,%Usr%,%perm%,%Inherit%

Hide comments


  • Allowed HTML tags: <em> <strong> <blockquote> <br> <p>

Plain text

  • No HTML tags allowed.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.