中国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-29 08:05
47,816 topics / 349,916 posts / today 0 new / 48,265 members
DOS批处理 & 脚本技术(批处理室) » How to write a BAT file to delete a specified file
Printable Version  3,469 / 14
Floor1 gslingyun Posted 2006-06-28 16:54
初级用户 Posts 9 Credits 26
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.
Floor2 electronixtar Posted 2006-06-28 17:00
铂金会员 Posts 2,672 Credits 7,493
Under NT


In pure DOS, using deltree is the simplest
Floor3 gslingyun Posted 2006-06-28 17:04
初级用户 Posts 9 Credits 26
Floor4 bagpipe Posted 2006-06-28 17:41
银牌会员 Posts 425 Credits 1,144 From 北京
for /l %a in (1,1,4) do rd /s /q e:\game\%a Hehe..............
Floor5 不得不爱 Posted 2006-06-28 18:58
超级版主 Posts 2,044 Credits 5,310 From 四川南充
Try it to know!
Floor6 gslingyun Posted 2006-06-28 19:33
初级用户 Posts 9 Credits 26
Ha~~~~Tried it... it works.. Thanks
Floor7 3742668 Posted 2006-06-28 22:52
荣誉版主 Posts 718 Credits 2,013
The bagpipe at 4F is really boring, but I decide to be more boring than you:

No.1:


No.2:
Floor8 220110 Posted 2006-06-29 00:33
荣誉版主 Posts 313 Credits 718
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 ]
Floor9 3742668 Posted 2006-06-29 01:28
荣誉版主 Posts 718 Credits 2,013
```
@echo off
if "%1" == "" echo The command format is: %0 directory1 directory2 directory3...
for %%i in (%*) do rd /s /q e:\game\%%i\
Floor10 xiongwei2624 Posted 2006-06-29 11:09
初级用户 Posts 44 Credits 96 From 深圳
Strong, learned, can you make this thing that can solve problems a little bit into a longer one! For example, a page!
Floor11 electronixtar Posted 2006-06-29 11:32
铂金会员 Posts 2,672 Credits 7,493
I'm bored



Test environment: WinXP SP2 Cmd5.1
Floor12 htysm Posted 2006-06-30 10:11
高级用户 Posts 415 Credits 866
It's really that experts have different approaches when competing. One problem can have many kinds of solutions.

This post is good, thumbs up.
Floor13 Li103Z Posted 2007-11-17 19:02
初级用户 Posts 38 Credits 70
electronixtar's
cd /d E:\game
rd /s /q 1 2 3 4
Not bad
Floor14 handan Posted 2007-11-25 17:58
初级用户 Posts 12 Credits 30
@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
Floor15 INeverAsk Posted 2007-11-25 19:14
初级用户 Posts 42 Credits 97
Learned, borrowed
[ Contact the Union admin team - 中国DOS联盟 - Standard version ]
Sponsored by ifanr Inc | © 2001–2023