namejm (闭关中)当前离线
批处理代码写手
荣誉版主
@echo off set "destination=" set "num=10" :: 以上两句可指定要处理的路径及文件数量 setlocal enabledelayedexpansion cd.>remain.txt for /f "delims=" %%i in ('dir /ad /b /s "%destination%"^|sort /r 2^>nul') do ( set count=0 set flag= for /f "delims=" %%j in ('dir /a-d /b "%%i" 2^>nul') do ( set /a count+=1 ) if !count! geq %num% ( set flag=yes ) else ( findstr /ic:"%%i\\" remain.txt>nul&&set flag=yes ) if not defined flag ( rd /q /s "%%i" ) else ( echo "%%i\">>remain.txt ) ) pause复制代码
@echo off :: 删除当前目录下所有空文件夹 for /f "delims=" %%i in ('dir /ad /b /s^|sort /r 2^>nul') do rd /q "%%i" 2>nul pause复制代码
caruko 当前离线
中校
TOP
rem 得到每个路径下文件数 for /r %%i in (*) do ( set /a #%~dpi+=1 ) rem 遍历路径,如果路径<10,搜索子路径,如果子路径下没有>=10的路径存在则删除,否者保留。 for /f "tokens=1,2 delims==" %%a in ('set #') do ( if %%b lss 10 ( set "flag=" for /f "tokens=1,2 delims==" %%x in ('set #%%a') do ( if %%y geq 10 set "flag=@" ) if not defined flag rd /q "%%a" ) )复制代码
CrLf 当前离线
论坛巡查
@echo off 2>nul 3>nul for /f "delims=" %%a in ('dir /ad /b /s "%destination%"^|sort /r 2^>nul') do ( for /f "skip=10 delims=" %%b in ('if not exist "%%a\*\" dir /a-d "%%a\"') do rd /s /q %%a )复制代码
随风 当前离线
@echo off set "destination=" set "num=10" setlocal enabledelayedexpansion for /f "delims=" %%i in ('dir /ad /b /s^|sort /r 2^>nul') do ( rd /q "%%i" 2>nul set count=0 set flag= for /f "delims=" %%j in ('dir /a-d /b "%%i" 2^>nul') do ( set /a count+=1 ) if !count! lss %num% ( set flag= for /f "delims=" %%j in ('dir /ad /b "%%i" 2^>nul') do set flag=remain if not defined flag rd /q /s "%%i" 2>nul ) ) pause复制代码
broly (Broly)当前离线
版主