JSI Tip 0729. Who owns that file and/or folder?

Supplement Two of the NT 4.0 Server Resource Kit contains SubInAcl which can display the owner of a file and/or folder.

WhoOwns.bat will build a CSV (Comma Seperated Value) file that contains a file and/or folder and the owner. Optionally, if the object is a folder, it will list the files and/or sub-folders that have different ownership.

The syntax is:

WhoOwns "<Path>" "csvfile" \[/n\] \[/f\] \[/s\] where:

 Parameter   D e s c r i p t i o n 
 "<Path>"   The folder or file you wish to query. It must be on a local drive. 
 "csvfile"   The CSV file that will contain the results of the query. 
 /n   List file names in the folder that have a different owner. 
 /f   List sub-directory names in the folder that have a different owner. 
 /s   Process the entire "<Path>" tree  

WhoOwns.bat contains:

@echo off
if %1

"" goto syntax
if not exist %1 goto syntax
if %2

"" goto syntax
if exist %2 del /q %2
set subs=
set nam=
set fold=
if /i "%3"

"/s" set subs=/s
if /i "%4"

"/s" set subs=/s
if /i "%5"

"/s" set subs=/s
if /i "%3"

"/f" set fold=/f
if /i "%4"

"/f" set fold=/f
if /i "%5"

"/f" set fold=/f
if /i "%3"

"/n" set nam=/n
if /i "%4"

"/n" set nam=/n
if /i "%5"

"/n" set nam=/n
if "%3"

"" goto pok
if /i "%3"

"/s" goto pok
if /i "%3"

"/f" goto pok
if /i "%3"

"/n" goto pok
:syntax
@echo Syntax error: WhoOwns "<Path>" "csvfile" \[/n\] \[/f\] \[/s\]
goto endc
:pok
if exist %1\*.* goto folder
if /i "%3"

"/s" goto syntax
if /i "%3"

"/f" goto syntax
if /i "%3"

"/n" goto syntax
:folder
set who1=%1
set who1=%who1:"=%
set who1=%who1%!
set who2=%who1%
set who2=%who2:\!=!%
if not "%who1%"

"%who2%" goto syntax
set who1=%1
set who1=%who1:"=%
set who2=%who1%
set who2=%who2:.*=%
if not "%who1%"

"%who2%" goto syntax
set who1=%1
set who1=%who1:"=%
set who2=
for /f "Tokens=1*" %%i in ('SubInAcl /noverbose /file %1') do call :owner "%who1%" %2 %%i %%j
if "%3"

"" goto endc
if /i "%subs%"

"/s" goto subs
if /i "%fold%"

"/f" goto nsfold
if /i "%nam%"

"/n" goto nsnam
goto endc
:nsfold
for /f "Tokens=*" %%i in ('dir %1 /b /ad') do call :preown "%who1%\%%i" %2
if /i "%nam%"

"/n" goto nsnam
goto endc
:nsnam
for /f "Tokens=*" %%i in ('dir %1 /b /a-d') do call :preown "%who1%\%%i" %2
goto endc
:subs
if /i "%fold%"

"/f" goto ysfold
if /i "%nam%"

"/n" goto ysnam
goto endc
:ysfold
for /f "Tokens=*" %%i in ('dir %1 /b /ad /s') do call :preown "%%i" %2
if /i "%nam%"

"/n" goto ysnam
goto endc
:ysnam
for /f "Tokens=*" %%i in ('dir %1 /b /a-d /s') do call :preown "%%i" %2
goto endc
:preown
for /f "Tokens=1*" %%i in ('SubInAcl /noverbose /file %1') do call :owner %1 %2 %%i %%j
goto end
:owner
if not "%3"

"/owner" goto end
if "%who2%"

"" goto first
if "%who2%"=="%4" goto end
@echo %1,%4>>%2
goto end
:first
set who2=%4
@echo %1,%4>>%2
goto end
:endc
set who=
set who1=
set who2=
set subs=
set nam=
set fold=
:end

Hide comments

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.
Publish