中国DOS联盟论坛

China DOS Union

-- Unite DOS · Advance DOS · Grow DOS --
Union site: www.cn-dos.net Forum site: www.cn-dos.net/forum
Guest | Log in | Register | Members | Search | China DOS Union
中国DOS联盟论坛
The time now is 2026-08-12 01:16
47,811 topics / 349,897 posts / today 0 new / 48,256 members
DOS批处理 & 脚本技术(批处理室) » Automatically determine whether the folder is empty. If it is an empty folder, delete it!
Printable Version  4,317 / 16
Floor1 eckert Posted 2008-02-22 00:47
初级用户 Posts 14 Credits 41
Automatically determine whether a folder is empty. If it is an empty folder, delete it!

for /l %%a in (1,1,3) do for/r %%i in (.) do rd %%~si

Let me see if there are any errors.

Can it be used in LJ file cleaning?
Floor2 lotus516 Posted 2008-02-23 00:53
高级用户 Posts 246 Credits 551
for /f "tokens=*" %%a in ('dir /b /ad /s "l:\"^|sort /r" do rd "%%a" 2>nul
Floor3 cad55 Posted 2008-02-23 09:26
高级用户 Posts 329 Credits 620
Originally posted by lotus516 at 2008-2-23 12:53 AM:
for /f "tokens=*" %%a in ('dir /b /ad /s "l:\"^|sort /r') do rd "%%a" 2>nul


Expert...

Also, may I ask...

How to search and delete all types of files with 0 bytes.
Floor4 zyz0304360 Posted 2008-02-23 11:33
中级用户 Posts 123 Credits 257 From 烟台
Indeed powerful
Learned
Salute
All types of files with 0 bytes
Use %%~z in FOR to expand the file size
%%~zi=0 means 0 bytes i
Floor5 zyz0304360 Posted 2008-02-23 11:40
中级用户 Posts 123 Credits 257 From 烟台
What does "l:\" mean in the following?
I don't understand here, can you give me some guidance?
Thank you very much
Floor6 cad55 Posted 2008-02-23 12:16
高级用户 Posts 329 Credits 620
Originally posted by zyz0304360 at 2008-2-23 11:40 AM:
May I ask
In the line "for /f "tokens=*" %%a in ('dir /b /ad /s "l:\"^|sort /r') do rd "%%a" 2>nul ",
what does the part "l:\" mean?
I don't understand this part here...



Dizzy
It's to delete the folders in the current drive letter.......


The 0-byte one.. you can say it again.....
I didn't understand it..........
Floor7 abcd Posted 2008-02-23 13:01
银牌会员 Posts 739 Credits 1,436
It is to use the characteristics of the rd command. When deleting a 0-byte folder, it will not prompt an error.
Floor8 zyz0304360 Posted 2008-02-23 13:05
中级用户 Posts 123 Credits 257 From 烟台
@echo off
for /f "tokens=*" %%i in ('dir /b *.* ^|sort /r') do if %%~zi==0 del /f /q "%%~ni.*"
pause

[ Last edited by zyz0304360 on 2008-2-23 at 01:18 PM ]
Floor9 zyz0304360 Posted 2008-02-23 13:26
中级用户 Posts 123 Credits 257 From 烟台
Originally posted by cad55 at 2008-2-23 12:16 PM:

Wow
It's to delete the current drive letter of the folder.......

Which 0-byte.. you say again.....
Didn't understand..........


It's to delete the current drive letter of the folder.......

I execute
dir /b /ad /s "|:\"
and it will report an error
Cannot find the specified path ah

For example, there is such a file
C:aa\aa\aa
How to delete the drive letter?
Like this?
C:aa\aa\aa |:\

I'm a newbie, currently only understand this
set a=C:aa\aa\aa
set a=%a:\=%

The above is not understood, please give guidance, thank you
Floor10 duansuo Posted 2008-02-23 15:07
新手上路 Posts 2 Credits 4
Is there anyone who can explain it completely? I still don't quite understand. Thanks a lot!
Floor11 abcd Posted 2008-02-23 16:50
银牌会员 Posts 739 Credits 1,436
Originally posted by zyz0304360 at 2008-2-23 01:26 PM:

It is to delete the current drive letter of the folder.......

I execute
dir /b /ad /s "|:\"
and it will report an error
Cannot find the specified path.

For example, there is such a file
C:aa\aa\aa
How to delete the drive letter...

Removing "|:\" means the current drive letter.

Replace "|:\" with your own path.
Floor12 cad55 Posted 2008-02-23 17:04
高级用户 Posts 329 Credits 620
Originally posted by duansuo at 2008-2-23 03:07 PM:
Is there anyone who can explain it completely? I still don't understand it very well.

Thanks!



For example: You want to delete empty folders under the C drive:
for /f "tokens=*" %%a in ('dir /b /ad /s "c:\"^|sort /r') do rd "%%a" 2>nul



You want to delete empty folders under the D drive:
for /f "tokens=*" %%a in ('dir /b /ad /s "d:\"^|sort /r') do rd "%%a" 2>nul

[ Last edited by cad55 on 2008-2-23 at 05:14 PM ]
Floor13 Nickey Posted 2008-02-23 17:15
初级用户 Posts 59 Credits 132 From GuangZhou
Why does changing the

to:

result in all folders being written to the notepad?
Floor14 abcd Posted 2008-02-23 17:18
银牌会员 Posts 739 Credits 1,436
Originally posted by Nickey at 2008-2-23 05:15 PM:
Why change the

to:
Floor15 zyz0304360 Posted 2008-02-23 18:06
中级用户 Posts 123 Credits 257 From 烟台
Originally posted by Nickey at 2008-2-23 05:15 PM:
Why change the

to:
1 2  Next
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023