我正在尝试编写一个批处理脚本来清理编译目录中的旧数据。它必须在某个头目录中进行搜索。在那里,它应该删除超过7天的文件,但只能在名称中包含单词“编译”的子文件夹中删除。compile335,compile336...
这就是我到目前为止想出的方法,但它不能正常工作:
REM Remove files older than 7 days in compile directories of headDirectory
cd C:\headDirectory
FOR /d /r . %%d IN (%Compile%\*) DO forfiles /p %%d /s /m *.* /d -7 /c "cmd /c Del @path" 你能告诉我该如何修改我的脚本吗?
编辑:
也许我的问题不够清楚。我想要能做到这一点的东西:
forfiles -p "C:\Whatever\Compile1" -s -m *.* -d -7 -c "cmd /c del @path"
forfiles -p "C:\Whatever\CompileFoo" -s -m *.* -d -7 -c "cmd /c del @path"
forfiles -p "C:\Whatever\CompileBar" -s -m *.* -d -7 -c "cmd /c del @path"
forfiles -p "C:\Whatever\Compile23" -s -m *.* -d -7 -c "cmd /c del @path"但是在一个循环语句中,该语句处理该目录中的所有编译文件夹,但保留其他文件夹不变。
发布于 2017-12-11 17:16:35
找到了,它是
CD C:\HeadDIrectory
FOR /D /r %%G in ("*Compile*") DO forfiles -p %%G -s -m *.* -d -7 -c
"cmd /c del @path"我用VB脚本调用它,让它变得安静:
Set WshShell = CreateObject("WScript.Shell" )
WshShell.Run chr(34) & "path\mybatch.bat" & Chr(34), 0
Set WshShell = Nothing你们知道更优雅的保持安静的方法吗?
https://stackoverflow.com/questions/47720853
复制相似问题