recurse and conditionally apply command line permissions using FOR statement

  • Thread starter Thread starter Ryan Rupert
  • Start date Start date
R

Ryan Rupert

I have a command line utility for NTFS permissions editing
(http://setacl.sourceforge.net) that requires an absolute path to do
its magic. If curious why I need to use this it is because it is the
only way I have found to ONLY perform the Windows 2000 ACL "reset
permissions on all child objects and enable propagation of inheritable
permissions". I want to recurse a folder tree and ONLY apply
permissions changes on folders of the same name. So, I come up with
this:

FOR /R /D %%A IN ("folder name") DO setacl.exe -on "%%A" <setacl
options>

My problem is that when the FOR statement provides the value at %%A it
is something like this:

C:\folderA\folderB\folder name\"folder name"

How can I configure the FOR statement to only provide the full path to
matching directories? Also, the FOR result for matching directories
must NOT end with a forward slash. So, this is the result I want from
this FOR operation:

C:\folderA\folderB\folder name
 
Ryan said:
I have a command line utility for NTFS permissions editing
(http://setacl.sourceforge.net) that requires an absolute path to do
its magic. If curious why I need to use this it is because it is the
only way I have found to ONLY perform the Windows 2000 ACL "reset
permissions on all child objects and enable propagation of inheritable
permissions". I want to recurse a folder tree and ONLY apply
permissions changes on folders of the same name. So, I come up with
this:

FOR /R /D %%A IN ("folder name") DO setacl.exe -on "%%A" <setacl
options>

My problem is that when the FOR statement provides the value at %%A it
is something like this:

C:\folderA\folderB\folder name\"folder name"

How can I configure the FOR statement to only provide the full path to
matching directories? Also, the FOR result for matching directories
must NOT end with a forward slash. So, this is the result I want from
this FOR operation:

C:\folderA\folderB\folder name

IIRC this erroneous behavior was recently discovered in this ng. Your
usage of /R with /D switches doesn't seem correct.
To circumvent the problem i'd use :

for /F "tokens=*" %%A in ('dir /B /S /AD "folder name"') do (
setacl.exe -on "%%~fA" <setacloptions>
)

HTH
 
IIRC this erroneous behavior was recently discovered in this ng. Your
usage of /R with /D switches doesn't seem correct.
To circumvent the problem i'd use :

for /F "tokens=*" %%A in ('dir /B /S /AD "folder name"') do (
setacl.exe -on "%%~fA" <setacloptions>
)

HTH

Thanks for the help, this is exactly what I needed, hopefully it will
help others in the future.
 
Back
Top