我有这个脚本,它通过尝试重命名目录来检查目录是否正在被使用,另外,检查它是否包含一些已知的临时文件。它工作得很好,除非它遇到一个带有所述临时文件的目录。
:: open each top dir for inspection and processing
for /d %%r in (*) do (
rem security
cd /d "%target%"
ren "%%r" "%%r(ctest)" || goto skip
ren "%%r(ctest)" "%%r" || goto skip
cd /d "%%r" || goto skip
dir /s *.!qb *.part *.dash* *.tmp >nul 2>nul && cd .. && goto skip
if defined verbose echo importing "%%~nxr"
rem call any scripts in the subdir with this script's own name
for /r "%~dp0%~n0\" %%s in (*.cmd) do call "%%s"
:skip
rem keep this (label can't be last)
echo done with "%%r"
)
不知何故,该行之后dir /s *.!qb *.part *.dash* *.tmp >nul 2>nul && cd .. && goto skip
脚本停止,并且我得到输出done with "%r"
,其中每个其他目录都显示目录名称%%r
,所以done with "directory name"
是预期的。