@echo off for /f "tokens=*" %%a in ('dir /b /ad /s "目标文件夹"^|sort /r') do rd "%%a" 2>nul pause goto :eof @echo off for /f "delims=" %%i in ('dir /ad /b /s') do call :rd_dir_empty "%%i" goto :eof
rem ======= 删除空目录 ========= :rd_dir_empty rd %1 2>nul||goto :eof set dir_route=%1 for /f "delims=" %%i in (%dir_route%) do ( set dir_route="%%~dpi" for /f "delims=" %%j in ('dir /ad /b "%%~dpi"')do rd "%%~dpi%%j" 2>nul||goto :eof ) :: 把路径最后的/去掉,以便set route_deepest="%%~dpi"能取到上一层路径 if "%dir_route:~-2,1%"=="/" set dir_route="%dir_route:~1,-2%" if /i not "%cd%"==%dir_route% call :rd_dir_empty %dir_route% goto :eof
第一步:进入Windows的MS-DOS窗口(Windows 2000/XP叫命令行提示符),进入要查找空文件夹的驱动器,执行: dir /ad/b/s | sort /r >empties.bat。 小提示