for /f "tokens=*" %%f in (
'dir /ad /s /b "d:\Batch_script\destiantion1"'
) do if exist "%%~f\dummy.txt" echo %%~f
对于每个命名下d destiantion1目录:\ batch_script,如果它包含一个dummy.txt文件,回声安慰
编辑 - 适应评论
for /f "tokens=*" %%f in (
'dir /ad /s /b "d:\Batch_script\destiantion1"'
) do if exist "%%~f\dummy.txt" (
dir /a-d /b "%%~f\dummy.txt" 2>nul | find "dummy.txt" > nul && echo %%~f
)
for
和dir
命令在搜索时不区分大小写,因此请使用过滤器。如果找到字符串,则不会设置错误级别并执行&&
之后的代码。
另一种方法是处理文件搜索的adecuated文件夹的完整列表/文件
for /f "delims=" %%f in (
'dir /a-d /s /b "d:\batch_script\dummy.txt" ^| findstr /l /e /c:"\destiantion1\dummy.txt"'
) do echo %%~dpf
由于它的工作很大。有没有什么方法可以用“if exists”命令检查区分大小写的文件?因为我的dummy.txt文件应该总是使用小写字母。 – user3327200
非常感谢,我现在都准备好和脚本一起去了:) – user3327200