我试图找出一个win命令行来删除所有不包含* .nes并将输出重定向到日志文件的子文件夹。
答案 0 :(得分:0)
这将删除批处理脚本所在文件夹中的任何子文件夹,该文件夹中没有.nes结尾的文件(甚至在子子文件夹中的任何位置)。小心这个脚本如果你不小心测试就不能轻易撤消。运行时不会发出警告。
@echo off
:: do not use if you don't know
:: what you are doing!
::
:: this file deletes all subfolders
:: without files with *.nes in them
:: WARNING: use with extreme care!
echo --- cleanup on %date% %time:~0,-3%% --- >> removed.log
for /D %%i in (*) do (
dir /b /s ".\%%i\*.nes" >NUL 2>NUL
if errorlevel 1 ( :: dir sets errorlevel 1 if no file is found
rmdir /q /s "%%i"
echo. removed %%i >> removed.log
)
set errorlevel=0
)
echo. >> removed.log