简体   繁体   English

批处理文件以在具有特定名称的文件夹和子文件夹上运行命令

[英]batch file to run command on folder and sub-folders with specific name

i need to run a command我需要运行一个命令

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

on every folder with name "UploadFiles" or "Newsletter" or "somethingelse" in ac:\\inetpub\\wwwroot在 ac:\\inetpub\\wwwroot 中名为“UploadFiles”或“Newsletter”或“somethingelse”的每个文件夹上

i used the dir command to extract all folders and then run a long batch file for each "row" (folder)我使用 dir 命令提取所有文件夹,然后为每个“行”(文件夹)运行一个长批处理文件

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?我如何使用 for 命令来做同样的工作?

you can do create a variable with all your match criteria, then run a for loop for each match:您可以使用所有匹配条件创建一个变量,然后为每个匹配运行 for 循环:

@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.通过这种方式,您可以使用相关搜索条件更新%vars%变量。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 批处理文件将文件夹移动到子文件夹 - Batch file to move folders to sub-folders 批处理文件以运行具有不同名称的文件夹和子文件夹中的 all.bat 文件 - Batch file to run all .bat files in folders and sub-folders with different names 批处理脚本复制带有文件的文件夹结构跳过特定的子文件夹 - Batch script to copy folder structure with files skip specific sub-folders 命令列出文件夹中的所有文件以及 Windows 中的子文件夹 - Command to list all files in a folder as well as sub-folders in windows Windows批处理文件-显示所有子文件夹 - Windows batch file - display all sub-folders 删除包含在不同子文件夹中的同名文件 - Delete file with same name contained in different sub-folders 批处理 - 如果文件夹包含特定的子文件夹,请移动它 - batch - if folders contains the specific sub folder move it Autorun.inf无法处理文件夹名称中包含空格的子文件夹? - Autorun.inf cannot deal with the sub-folders with space in their folder name? 批处理命令删除具有特定名称和年龄的文件夹 - Batch command to delete folders with specific name and age 如何在Windows中获得具有特定名称的所有子文件夹的计数? - How can I get a count of all sub-folders with a specific name in Windows?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM