- Set permissions on directory tree
- Posted by john@aoitconsulting.com on July 2nd, 2008
I am trying to set permissions on 4 levels of directories. The first
three levels should all be set to WFAdmins to have full rights, domain
admins to have full rights, and everyone else to have read and list
rights.
The trick here is that the 4th level needs to have all files and
subfolders to have everyone set as full access.
How do I create a routine that will set my two different levels of
permissions on directories in such a structure?
Thank you for the help!
- Posted by foxidrive on July 3rd, 2008
On Wed, 2 Jul 2008 15:42:55 -0700 (PDT), john@aoitconsulting.com wrote:
Count the backslashes and use the count variable to identify which set of
permissions should be applied.
Some example folder structures would be useful for a solution (need to know
if the 4 levels are 2 to 6 levels deep from the root for example).
- Posted by john@aoitconsulting.com on July 3rd, 2008
W:\001\090\023\Emails\Email1.Eml
Would be an example of a full address to Email1.eml
I would guess that I would be using a dir /b /s > directory.txt to get
the directory structure in a file
Then I would be using a for %%z in (directory.txt) do cacls /g
everyone:f %1
not sure though on how to count the backslashes, or if my commands are
the correct ones.
Thank you for the replies.
On Jul 2, 7:51 pm, foxidrive <got...@woohoo.invalid> wrote:
- Posted by billious on July 3rd, 2008
<john@aoitconsulting.com> wrote in message
news:f2fb4603-2067-4902-8b3e-ff4335504ecc@i36g2000prf.googlegroups.com...
This solution developed using XP
It may work for NT4/2K
----- batch begins -------
[1]@echo off
[2]del result1.txt 2>nul
[3]del result2.txt 2>nul
[4]del result3.txt 2>nul
[5]del result4.txt 2>nul
[6]for /f "tokens=*" %%i in ( ' dir /s/b/a:d \106x ' ) do for /f
"tokens=3*delims=\" %%a in ("%%i") do set ysl=%%b&if defined ysl
(>>result1.txt echo\%%i) else (>>result2.txt echo\%%i)
[7]for /f "tokens=*" %%i in ( ' dir /s/b/a:-d \106x ' ) do for /f
"tokens=3*delims=\" %%a in ("%%i") do set ysl=%%b&if defined ysl
(>>result3.txt echo\%%i) else (>>result4.txt echo\%%i)
------ batch ends --------
Lines start [number] - any lines not starting [number] have been wrapped and
should be rejoined. The [number] that starts the line should be removed
The spaces surrounding the single-quotes are for emphasis only. The SPACES
are not required but the single-quotes ARE required.
C:\106x... is my test directory.
result 1 and result2 contain the list of directories which have 3 or more
levels/fewer than 3 levels
result 3 and result4 contain the list of files which have 3 or more
levels/fewer than 3 levels of directory.
....that should get you started.
- Posted by foxidrive on July 3rd, 2008
On Wed, 2 Jul 2008 21:49:27 -0700 (PDT), john@aoitconsulting.com wrote:
This code will allow you to set the permissions for the files in the folder
at each level from the root folder. The cd by itself just reports the
folder it is in - so run it and see what is echoed.
@echo off
setlocal
for /f "tokens=1-6 delims=\" %%a in ('dir /a:d /o:n /b /s') do (
if "%%f"=="" if not "%%e"=="" (
cd "%%a\%%b\%%c\%%d\%%e"
cd
echo cacls level 4
cd..
cd
echo cacls level 3
cd..
cd
echo cacls level 2
cd..
cd
echo cacls level 1
pause
)
)
- Posted by John Rivers on July 4th, 2008
I removed the cd commands and ran the cacls commands on %%a\%%b\%%c\%%d
\%%e and %%a\%%b\%%c\%%d and %%a\%%b\%%c and it works like a champ.
Thank you so much.
Also thank you billious for the response, but I couldn't understand
the scripting, and was afraid that I would kill it when I edited it.
On Jul 3, 1:57*am, foxidrive <got...@woohoo.invalid> wrote: