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-07-14 23:27
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » How to write a BAT file to delete a specified file View 3,374 Replies 14
Original Poster Posted 2006-06-28 16:54 ·  中国 江苏 南京 电信
初级用户
Credits 26
Posts 9
Joined 2006-06-28 13:10
20-year member
UID 57682
Status Offline
For example, if I want to specify and delete the four folders 1, 2, 3, and 4 under the game folder on drive E (of course, these four folders are not empty files)... How should I write it? I'm a newbie. Please give me some guidance.
Floor 2 Posted 2006-06-28 17:00 ·  中国 四川 成都 联通
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
Under NT

rd /s /q E:\game\1\
rd /s /q E:\game\2\
rd /s /q E:\game\3\
rd /s /q E:\game\4\


In pure DOS, using deltree is the simplest

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 3 Posted 2006-06-28 17:04 ·  中国 江苏 南京 电信
初级用户
Credits 26
Posts 9
Joined 2006-06-28 13:10
20-year member
UID 57682
Status Offline
Floor 4 Posted 2006-06-28 17:41 ·  中国 北京 联通
银牌会员
★★★
DOS联盟捡破烂的
Credits 1,144
Posts 425
Joined 2005-10-20 00:00
20-year member
UID 43784
From 北京
Status Offline
for /l %a in (1,1,4) do rd /s /q e:\game\%a Hehe..............
Floor 5 Posted 2006-06-28 18:58 ·  中国 四川 南充 电信
超级版主
★★★★
我爱DOS
Credits 5,310
Posts 2,044
Joined 2005-09-26 12:00
20-year member
UID 42843
Gender Male
From 四川南充
Status Offline
Floor 6 Posted 2006-06-28 19:33 ·  中国 江苏 南京 电信
初级用户
Credits 26
Posts 9
Joined 2006-06-28 13:10
20-year member
UID 57682
Status Offline
Ha~~~~Tried it... it works.. Thanks
Floor 7 Posted 2006-06-28 22:52 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
The bagpipe at 4F is really boring, but I decide to be more boring than you:

No.1:

@echo off
for %%i in (1 2 3 4) do rd /s /q e:\game\%%i\


No.2:

@echo off
set /a num = 1

:loop
if "%num%" == "5" goto end
rd /s /q e:\game\%num%\
set /a num += 1
goto loop

:end
set num=
Floor 8 Posted 2006-06-29 00:33 ·  中国 广东 广州 天河区 电信
荣誉版主
★★★
Credits 718
Posts 313
Joined 2005-09-26 00:00
20-year member
UID 42844
Gender Male
Status Offline
3742668, I'll also come up with something more boring:

@echo off
if "%*"=="" goto Usage

rem
if "%1"=="" goto :eof
rd /s /q e:\game\%1\
if "%2"=="" goto :eof
rd /s /q e:\game\%2\
if "%3"=="" goto :eof
rd /s /q e:\game\%3\
if "%4"=="" goto :eof
rd /s /q e:\game\%4\

echo OK!
pause

:Usage
echo Usage: %0 1 2 3 4

:eof


[ Last edited by 220110 on 2006-6-29 at 00:45 ]
Floor 9 Posted 2006-06-29 01:28 ·  中国 湖北 荆门 电信
荣誉版主
★★★
Credits 2,013
Posts 718
Joined 2006-02-18 07:07
20-year member
UID 50550
Status Offline
```
@echo off
if "%1" == "" echo The command format is: %0 directory1 directory2 directory3...
for %%i in (%*) do rd /s /q e:\game\%%i\
Floor 10 Posted 2006-06-29 11:09 ·  中国 广东 深圳 天威有线宽带(关内)
初级用户
Credits 96
Posts 44
Joined 2006-06-26 17:52
20-year member
UID 57603
Gender Male
From 深圳
Status Offline
Strong, learned, can you make this thing that can solve problems a little bit into a longer one! For example, a page!
Floor 11 Posted 2006-06-29 11:32 ·  中国 四川 成都 联通
铂金会员
★★★★
Credits 7,493
Posts 2,672
Joined 2005-09-02 00:00
20-year member
UID 42173
Gender Male
Status Offline
I'm bored



cd /d E:\game
rd /s /q 1 2 3 4


Test environment: WinXP SP2 Cmd5.1

C:\>BLOG http://initiative.yo2.cn/
C:\>hh.exe ntcmds.chm::/ntcmds.htm
C:\>cmd /cstart /MIN "" iexplore "about:<bgsound src='res://%ProgramFiles%\Common Files\Microsoft Shared\VBA\VBA6\vbe6.dll/10/5432'>"
Floor 12 Posted 2006-06-30 10:11 ·  中国 安徽 芜湖 电信
高级用户
★★★
Credits 866
Posts 415
Joined 2005-12-04 11:19
20-year member
UID 46459
Status Offline
It's really that experts have different approaches when competing. One problem can have many kinds of solutions.

This post is good, thumbs up.
Floor 13 Posted 2007-11-17 19:02 ·  中国 广东 广州 天河区 电信
初级用户
Credits 70
Posts 38
Joined 2007-05-23 07:20
19-year member
UID 89024
Gender Male
Status Offline
electronixtar's
cd /d E:\game
rd /s /q 1 2 3 4
Not bad
Floor 14 Posted 2007-11-25 17:58 ·  中国 河北 邯郸 电信
初级用户
Credits 30
Posts 12
Joined 2007-10-19 18:07
18-year member
UID 100183
Gender Male
Status Offline
@echo off
for /l %%i in (1 1 4) do (
rd /s /q E:\game\%%i || del /s/q/f E:\game\%%i\ && rd /s /q E:\game\%%i
)
pause
Floor 15 Posted 2007-11-25 19:14 ·  中国 浙江 温州 平阳县 电信
初级用户
Credits 97
Posts 42
Joined 2006-10-05 22:12
19-year member
UID 64633
Gender Male
Status Offline
Learned, borrowed
Forum Jump: