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-07 17:19
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to batch delete malformed folders? View 3,223 Replies 16
Original Poster Posted 2008-02-29 17:58 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
I downloaded a program and created 50 deformed folders on my desktop. The folder names are 1., 2.,... 50. How to batch delete them with a batch script? Please expert write a code!

[ Last edited by 5872169 on 2008-2-29 at 06:18 PM ]
Floor 2 Posted 2008-02-29 18:18 ·  中国 上海 联通
版主
★★★★★
Credits 9,023
Posts 5,017
Joined 2007-05-31 19:39
19-year member
UID 89899
Gender Male
Status Offline
Delete folders ending with a dot:

rd /a /q "1..\"
Floor 3 Posted 2008-02-29 18:19 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
Can I delete in batches? I'm tired of deleting one by one. I know this code. I only know that I can delete with the FOR command, but I don't know how to write it!
Floor 4 Posted 2008-02-29 18:52 ·  中国 陕西 西安 电信
初级用户
Credits 67
Posts 40
Joined 2008-01-31 23:57
18-year member
UID 109932
Gender Male
Status Offline
for /l %%a in (0 1 9) do (
for /l %%b in (0 1 9) do (
rd /q /s "%%a%%b..\" 2>nul
))
Floor 5 Posted 2008-02-29 18:57 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
The code on floor 4 doesn't work, can't delete it. Why is there no path! My folder name is 1. Not 01.!

[ Last edited by 5872169 on 2008-2-29 at 07:02 PM ]
Floor 6 Posted 2008-02-29 19:08 ·  中国 湖北 武汉 电信
新手上路
Credits 6
Posts 2
Joined 2008-02-29 17:32
18-year member
UID 111730
Gender Male
Status Offline
@echo off
rmdir c:\%systemdrive%\Documents and Settings\用户名\桌面\1...\ /s
pause
Floor 7 Posted 2008-02-29 19:09 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
I have more than one folder, there are too many, it's too troublesome to delete one by one! I want to use the FOR command to delete, but I don't know how to write it!
Floor 8 Posted 2008-02-29 19:10 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
```
@echo off

:DELF
if == goto :EOF
rd /s /q %1.\
shift
goto :DELF
```
正在潜水修练的批处理小白
Floor 9 Posted 2008-02-29 19:14 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
The code on the 8th floor doesn't work either!
Floor 10 Posted 2008-02-29 19:20 ·  中国 陕西 西安 电信
初级用户
Credits 67
Posts 40
Joined 2008-01-31 23:57
18-year member
UID 109932
Gender Male
Status Offline
If you are using the Chinese version of Windows:
@echo off
for /l %%a in (0 1 50) do rd /q /s "%userporfile%\Desktop\%%a%%b.." 2>nul
Floor 11 Posted 2008-02-29 19:24 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
The code on the 10th floor doesn't work either!
Floor 12 Posted 2008-02-29 19:26 ·  中国 广东 广州 电信
高级用户
★★★
潜水修练批处理
Credits 788
Posts 366
Joined 2006-12-31 02:43
19-year member
UID 75048
Gender Male
Status Offline
Originally posted by 5872169 at 2008-2-29 07:14 PM:
The code on floor 8 doesn't work either!


Is it prompting for access denied...

Just did an experiment, Windows has a limit on the maximum length of supported parameters. For folders on the desktop, probably at most 40 can be deleted simultaneously...

P.S. The %%b on floor 10 shouldn't be there
正在潜水修练的批处理小白
Floor 13 Posted 2008-02-29 19:28 ·  中国 陕西 西安 电信
初级用户
Credits 67
Posts 40
Joined 2008-01-31 23:57
18-year member
UID 109932
Gender Male
Status Offline
There is a %%b added above, make a small change:
for /l %%a in (1 1 50) do rd /q /s "%USERPROFILE%\Desktop\%%a..\"


[ Last edited by NeverAgain on 2008-2-29 at 07:29 PM ]
Floor 14 Posted 2008-02-29 19:32 ·  中国 山东 济南 联通
高级用户
★★★
Credits 959
Posts 474
Joined 2007-10-25 10:40
18-year member
UID 100716
Gender Male
Status Offline
Thanks a lot! It succeeded at the 13th floor! All deleted, and learned something again!
Floor 15 Posted 2008-02-29 20:13 ·  中国 陕西 西安 电信
银牌会员
★★★★
钻石会员
Credits 2,278
Posts 1,020
Joined 2007-11-19 13:34
18-year member
UID 103127
Gender Male
Status Offline
Do not run under the path where the ghost backup file is located!


:: Delete abnormal directories in the current path
for /f "delims=" %%a in ('dir/ad/b^|findstr /e "\."') do rd /q/s "%%a.\"


:: Delete abnormal directories in the current path, including subdirectories
for /f "delims=" %%a in ('dir/ad/s/b^|findstr /e "\."') do rd /q/s "%%a.\"


-----------------------------------------------------------------

Delete empty abnormal directories in the directory tree and display non-empty abnormal directories

for /f "delims=" %%a in ('dir/ad/s/b^|findstr /e "\."') do rd "%%a.\" 2>nul||echo %%a


[ Last edited by plp626 on 2008-2-29 at 08:57 PM ]
Forum Jump: