China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --

Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
DOS stands for freedom, openness and progress. Let us work hard, learn from the openness and GNU spirit of FreeDOS and Linux, and together build and grow a free GNU GPL world!

中国DOS联盟论坛
The time now is 2026-08-13 03:55
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help, how to use a for loop to delete empty directories View 1,562 Replies 6
Original Poster Posted 2008-07-02 15:06 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
How to use a for loop to delete empty directories
Floor 2 Posted 2008-07-02 20:58 ·  中国 陕西 西安 电信
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Like
for /r /d %%a in (*.*) do rd "%a"
Floor 3 Posted 2008-07-07 17:44 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
No answer, is the question too complicated?
Floor 4 Posted 2008-07-07 23:06 ·  中国 湖北 武汉 联通
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Since this issue has been discussed several times, there's no need to repeat answering your question.
Floor 5 Posted 2008-07-08 12:05 ·  中国 台湾 中华电信(HiNet)数据中心
初级用户
Credits 79
Posts 45
Joined 2007-11-28 15:10
18-year member
UID 104056
Gender Male
Status Offline
Thanks a lot.

Searched for "delete empty directory" and didn't find it.

Searched for "delete empty directory" and then found it.
Floor 6 Posted 2008-07-08 15:31 ·  中国 河北 保定 联通
铂金会员
★★★★
网络独行侠
Credits 6,962
Posts 2,753
Joined 2003-04-16 00:00
23-year member
UID 1565
Gender Male
From 河北保定
Status Offline

::::NAME RDEmpty.cmd Delete all empty directories under the specified directory.cmd
@echo off

if not == goto _loop
call :_rdit %cd%
goto :eof

:_loop
call :_rdit %1
shift
if not == goto _loop
goto :eof

:_rdit
for /f "usebackq tokens=*" %%i in (`dir /ad/b/s %1 ^| sort/r`) do rd /q "%%i" >nul 2>nul && echo RD "%%i" ... Done!
goto :eof
偶只喜欢回答那些标题和描述都很清晰的帖子!
如想解决问题,请认真学习“这个帖子”和“这个帖子”并努力遵守,如果可能,请告诉更多的人!
Floor 7 Posted 2010-01-06 09:04 ·  中国 江苏 南京 电信
初级用户
★★
Credits 138
Posts 50
Joined 2007-01-23 10:59
19-year member
UID 77428
Gender Male
Status Offline
What you're deleting a directory that's not empty!
Forum Jump: