批处理:Windows递归删除所有文件只保留扩展名.xxx并清空空目录

批处理:递归删除所有文件只保留扩展名.xxx并清空空目录

@echo off
set ROOTDIR=D:\folder\
for /f "delims=" %%F in ('dir %ROOTDIR% /s /b /a-d ^|findstr /vile ".js"') do del "%%F"
for /f "delims=" %%d in ('dir %ROOTDIR% /s /b /ad ^| sort /r') do rd "%%d"
pause

参考资料:

Recursively delete empty directories in Windows

Delete all files in subdirectories EXCEPT a given extension (in Windows BATCH)

Remove all files/directories except for one file

点赞