0

我正在尝试找出一个 win 命令行来删除所有不包含 *.nes 的子文件夹并将输出重定向到日志文件。

4

1 回答 1

0

This will delete any sub folder in the folder where the batch script is located that does not have a file with .nes ending inside it (anywhere even in sub sub folders). Be careful with this script it can not be easily undone if you test is carelessly. It does not warn when run.

@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
于 2013-03-15T19:29:21.340 回答