Home > Enterprise >  batch file to run command on folder and sub-folders with specific name
batch file to run command on folder and sub-folders with specific name

Time:11-02

i need to run a command

icacls "foldername" /deny IUSR:(OI)(CI)(X)

on every folder with name "UploadFiles" or "Newsletter" or "somethingelse" in a c:\inetpub\wwwroot

i used the dir command to extract all folders and then run a long batch file for each "row" (folder)

like that

icacls "folder1/UploadFiles" /deny IUSR:(OI)(CI)(X)
icacls "folder2/UploadFiles" /deny IUSR:(OI)(CI)(X)
icacls "folder3/Newsletter" /deny IUSR:(OI)(CI)(X)
icacls "folder4/ssss/Newsletter" /deny IUSR:(OI)(CI)(X)

how can i use the for command to do the same work?

CodePudding user response:

you can do create a variable with all your match criteria, then run a for loop for each match:

@echo off
set "vars="*UploadFiles*" "*Newsletter*" "*somethingelse*""
for /D %%i in (%vars%) do icacls "%%~i" /deny IUSR:(OI)(CI)(X)

This way you can update the %vars% variable with relevant search criteria.

  • Related