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-06-27 21:34
中国DOS联盟论坛 » 其它操作系统综合讨论区 » Delete all subdirectories under a directory (not including the parent directory) (Solved) View 2,174 Replies 10
Original Poster Posted 2008-01-01 15:31 ·  中国 广东 汕头 潮阳区 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
Question: delete all subdirectories under a directory (not including the parent directory)
If I want to delete all subdirectories under HAIOU, but keep the parent directory HAIOU itself.
Using RD/S/Q HAIOU will pull out the entire HAIOU directory by the roots.

[ Last edited by haiou327 on 2008-1-1 at 08:11 PM ]
Floor 2 Posted 2008-01-01 15:37 ·  中国 广东 汕头 潮阳区 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
RMDIR path
RD path

/S In addition to the directory itself, also deletes all subdirectories and
files under the specified directory. Used to delete a directory tree.


Using the /S parameter deletes the parent directory too
Floor 3 Posted 2008-01-01 16:35 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,282
Posts 538
Joined 2002-11-02 00:00
23-year member
UID 129
Gender Male
Status Offline
My idea: (not convenient to test, please test it yourself. I don't know if there are any mistakes)

if %%a in (dir/ad/b) do rd %%a /s /q
Floor 4 Posted 2008-01-01 19:15 ·  中国 广东 汕头 潮阳区 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
Floor 5 Posted 2008-01-01 19:29 ·  中国 广东 汕头 潮阳区 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
If there are a few hundred directories with random numbers in the HAIOU directory, and I want to delete those directories but keep the HAIOU directory,
how should a batch file like this be written.
C:\HAIOU
├─1
├─10
├─100
├─101
├─102
├─103
├─104
├─105
├─106
├─107
├─108
├─109
├─11
├─110
├─111
├─112
├─113
├─114
├─115
├─116
├─117
├─118
├─119
├─12
├─120
├─121
├─122
├─123
├─124
├─125
├─126
├─127
├─128
├─129
├─13
├─130
├─131
├─132
├─133
├─134
├─135
├─136
├─137
├─138
├─139
├─14
├─140
├─141
├─142
├─143
├─144
├─145
├─146
├─147
├─148
├─149
├─15
├─150
├─151
├─152
├─153
├─154
├─155
├─156
├─157
├─158
├─159
├─16
├─160
├─161
├─162
├─163
├─164
├─165
├─166
├─167
├─168
├─169
├─17
├─170
├─171
├─172
├─173
├─174
├─175
├─176
├─177
├─178
├─179
├─18
├─180
├─181
├─182
├─183
├─184
├─185
├─186
├─187
├─188
├─189
├─19
├─190
├─191
├─192
├─193
├─194
├─195
├─196
├─197
├─198
├─199
├─2
├─20
├─200
├─21
├─22
├─23
├─24
├─25
├─26
├─27
├─28
├─29
├─3
├─30
├─31
├─32
├─33
├─34
├─35
├─36
├─37
├─38
├─39
├─4
├─40
├─41
├─42
├─43
├─44
├─45
├─46
├─47
├─48
├─49
├─5
├─50
├─51
├─52
├─53
├─54
├─55
├─56
├─57
├─58
├─59
├─6
├─60
├─61
├─62
├─63
├─64
├─65
├─66
├─67
├─68
├─69
├─7
├─70
├─71
├─72
├─73
├─74
├─75
├─76
├─77
├─78
├─79
├─8
├─80
├─81
├─82
├─83
├─84
├─85
├─86
├─87
├─88
├─89
├─9
├─90
├─91
├─92
├─93
├─94
├─95
├─96
├─97
├─98
└─99

[ Last edited by haiou327 on 2008-1-1 at 07:33 PM ]
Floor 6 Posted 2008-01-01 20:07 ·  中国 广东 汕头 潮阳区 电信
高级用户
★★★
DOS时空
Credits 713
Posts 348
Joined 2007-02-10 13:59
19-year member
UID 79169
Gender Male
Status Offline
Already solved, thanks for chishingchan's hint, but it's FOR, not IF

Posting the code
for /f %%a in ('dir /ad /b /s c:\haiou') do rd /s/q %%a

[ Last edited by haiou327 on 2008-8-1 at 10:51 PM ]
Floor 7 Posted 2008-01-03 16:35 ·  中国 广东 东莞 电信
银牌会员
★★★
Credits 1,282
Posts 538
Joined 2002-11-02 00:00
23-year member
UID 129
Gender Male
Status Offline

Already solved, thanks for chishingchan's hint, but it's FOR, not IF


You're right, I just made a typo.
Floor 8 Posted 2008-07-24 15:52 ·  中国 陕西 西安 电信
初级用户
Credits 52
Posts 24
Joined 2007-08-24 08:31
18-year member
UID 95728
Gender Male
Status Offline
You play DOS commands so well, there are really a lot of talented people in the DOS Union. I still need to work harder
Floor 9 Posted 2008-07-25 23:07 ·  中国 广东 佛山 电信
初级用户
Credits 32
Posts 14
Joined 2007-08-28 16:42
18-year member
UID 96038
Gender Male
Status Offline
Actually you can use RD /S /Q and then create a HAIOU folder again
Floor 10 Posted 2010-07-27 09:13 ·  中国 广东 珠海 香洲区 电信
新手上路
Credits 6
Posts 3
Joined 2005-11-01 01:23
20-year member
UID 44385
Status Offline
Originally posted by haiou327 at 2008-1-1 20:07:
Already solved, thanks for chishingchan's hint, but it's FOR, not IF

Posting the code
for /f %%a in ('dir /ad /b /s c:\haiou') do rd /s/q %%a

After using it, it reports an error. My system is windows2003.
Floor 11 Posted 2010-08-01 00:14 ·  中国 湖南 常德 电信
银牌会员
★★★
Credits 1,384
Posts 709
Joined 2005-10-29 22:22
20-year member
UID 44271
Status Offline
Forum Jump: