我使用批处理脚本创建.bat文件以从绝对路径获取最后一个文件夹,然后与字符串进行比较。例如,我有:C:\ Scripts \(从我开始run.bat的位置)和子文件夹C:\ Scripts \ a \,C:\ Scripts \ b \ results,C:\ Scripts \ c \ results。我想要搜索名称为“结果”的文件夹,以及何时发现它做了某些操作(例如增加计数器)。批处理:从绝对路径获取最后一个文件夹并与字符串进行比较
set /A Counter=0
for /d /r %%F in (*.*) do (
set path=%FF
rem if the last folder from the path is = "results" then do some stuff
if path.contains("results") set /A Counter+=1
)
echo %Counter%
它应该写2 – Ice 2013-03-14 13:34:50