icacls batch file multiple directories with wildcards help needed
With the following directory tree:
The code below will apply the security permissions you specified to both of the directories called "specificfolder"
@echo off for /D %%f in ("D:\Data\3*") do for /D %%d in ("%%f\*") do icacls "%%d\specificfolder" /inheritance:r /grant:r "Domain Admins":(OI)(CI)F
NOTE - This uses nested FOR loops which is not supported by DOS (COMMAND.COM). This will work fine with a NT (CMD.EXE) system.
Related videos on Youtube
user153521 less than a minute
I have written the following batch file that does a great job combing through all folders beginning with the number 3 and applying folder permissions to any 2010 subfolder. Example of the batch filesis below:
for /D %%f in (D:\Data\3*) do icacls "%%f\2010" /inheritance:r /grant:r "Domain Admins":(OI)(CI)F
Question : How can I improve this script to allow for me to apply the permissions to a specific folder below ANY folder within the folders beginning with 3?
here is an example of my failed attempt:
for /D %%f in (D:\Data\3*) do icacls "%%f*\specificfolder" /inheritance:r /grant:r "Domain Admins":(OI)(CI)F
user153521 almost 10 yearsnote on my last line of code, the post is stripping a \ prior to the *
soandos almost 10 yearsCan you provide an example directory tree that you are working on?
user153521 almost 10 years@soandos Example Directory: D:\Data\3214 Client\Accounts\SpecificFolder The idea being it will look for the SpecificFolder within any Folder below the 3214 'Client Directory.'
user153521 almost 10 yearsThanks for your reply on this. The command in your answer is what I am currently using for everything within D:\Data\3* directories just as you stated, and it works great. I had placed the asterik in "%%f*\specificfolder" because I would like the script to drill down one more directory (with any name, which is the reason for the *) and look for the specific folder there. I hope this helps, let me know if I need to explain it in more detail.
James Mnatzaganian almost 10 yearsUpdated my original answer to reflect the directory structure you described above. If you want/need something more, let me know.
user153521 almost 10 yearsWe are close! I tried the code but it is cutting off the directory between client number and name due to the space. I have modified your most recent code as follows, I just added quotes around "%%f*": for /D %%f in (D:\Data\3*) do for /D %%d in ("%%f*") do icacls "%%d\specificfolder" Example: D:\Data\31245 Smith\anyfolder\specificfolder The problem is after the script runs through all the correct folders, it then repeats itself but it cuts off the Client directory prior to the space like the most recent code. Example: icacls D:\Data\31245\anyfolder\specificfolder
James Mnatzaganian almost 10 yearsI'm unable to replicate your problem. What bothers me is that you say the script repeats itself. Are you using this code in combination with some other code? I edited my answer again and also added quote around the
D:\Data\3*portion; however, on my system it worked just fine with only making the change you mentioned. Perhaps you are referring to it echoing? Try making a new batch file with the two lines of code in my answer, and let me know what happens. If it doesn't work, give me the full path you are using.
user153521 almost 10 yearsMy fault, the script did not repeat, I misinterpreted this yesterday with two similar named files in the test environment.
user153521 almost 10 yearsWorking code: - for /D %%f in (D:\Data\3*) do for /D %%d in ("%%f*") do icacls "%%d\specificfolder" /inheritance:r /grant:r "Domain Admins":(OI)(CI)F
user153521 almost 10 yearsSlayer537 you are the best, thank you for helping me make this work!!!!