E: est>dir /b /s|sort /r E: estc E: estb E: estb E: estaa.txt E: esta E: est>rd .a & rd . & rd .c 目录不是空的。 目录不是空的。 E: est>dir /b /s|sort /r E: estb E: estb E: estaa.txt E: esta
利用 rd 命令的特点,达到删除空目录的作用,但是谨慎使用,空目录不代表无意义。
@echo off rem ---------------------------------------------------------------------------- rem Script Name: Empty_remover rem Author Name: Tty725 rem Creation Date: 2019-11-05 rem Last Modified: 2019-11-05 rem Copyright (c)2019 rem Purpose: Delete an empty folder rem ---------------------------------------------------------------------------- if "%1"=="" (set folder=%cd%) else (set folder=%1) if not EXIST %folder% (echo directory does not exist:%folder% & goto bexit) dir %folder% /ad /b /s | sort /r > %folder%dir_adbs.pre for /f %%a in (%folder%dir_adbs.pre) do rd %%a dir %folder% /ad /b /s | sort /r > %folder%dir_adbs.post :bexit exit