2013-03-10 113 views
0

我想弄清楚一个win命令行来删除不包含* .nes并将输出重定向到日志文件的所有子文件夹。批处理脚本:删除不包含特定的子文件夹

+3

不包含\ *。nes *其中*?在文件夹名称?文件夹内的文件名?如果文件夹包含子文件夹,会发生什么情况? – 2013-03-10 19:21:48

回答

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 
相关问题