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-02 14:35
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Help, about deleting files with batch commands!! View 2,223 Replies 15
Original Poster Posted 2006-11-16 00:32 ·  中国 广东 深圳 罗湖区 电信
初级用户
Credits 128
Posts 9
Joined 2003-06-07 00:00
23-year member
UID 4227
Gender Male
Status Offline
I want to use a batch processing command to delete files. The file name is: xyz.com. How can I delete all xyz.com under the specified drive letter??? Thanks everyone, thank you.
Floor 2 Posted 2006-11-16 00:56 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Copy one for you, no need to specify, delete all.
@echo off
setlocal enabledelayedexpansion
for /f "delims=\" %%i in ('fsutil fsinfo drives^|find /v ""') do (
set var=%%i
set drive=!var:~-2!
fsutil fsinfo drivetype !drive!|find "Fixed">nul && del /a /f /s !drive!\xyz.com
)
pause

If you want to specify under the C drive, use del /a /f /s c:\xyz.com
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 3 Posted 2006-11-16 00:58 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
```
@echo off
set/p a=Please specify the drive letter of the file to be deleted: (Format like: C:)
set/p b=Please specify the file name to be deleted:
for /f "delims=" %%i in ('dir /s/b/a-d %a%\%b%') do del %%i
```
Floor 4 Posted 2006-11-16 02:40 ·  中国 广东 深圳 罗湖区 电信
初级用户
Credits 128
Posts 9
Joined 2003-06-07 00:00
23-year member
UID 4227
Gender Male
Status Offline
It seems that none can be deleted normally, but still thank you all
Floor 5 Posted 2006-11-16 02:44 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by xtay1625 at 2006-11-16 02:40:
It seems that none can be deleted normally, but thank you all the same


  Why can't it be deleted? Let's talk about your situation. The code can be appropriately modified to force deletion!

  It may not be deleted because it has a system attribute or the file is being used...
Floor 6 Posted 2006-11-16 02:44 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Why can't it be deleted normally? Please describe the situation.
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 7 Posted 2006-11-16 02:55 ·  中国 北京 朝阳区 联通
金牌会员
★★★★
Credits 2,902
Posts 1,147
Joined 2006-09-21 12:00
19-year member
UID 63324
Gender Male
Status Offline
The reason for the inability to delete normally is that the file to be deleted is in a directory with spaces ~:)
It must be that the "quotes" were forgotten to be written, haha ~:)
DEL "%%i"
……

Could it be that it's going to delete that "Viking" virus again? (That thing still infects executable files ~:)
Directly download the tool to specifically kill this virus from the virus official website ~:)

[ Last edited by redtek on 2006-11-16 at 02:58 AM ]
    Redtek,一个永远在网上流浪的人……

_.,-*~'`^`'~*-,.__.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._,_.,-*~'`^`'~*-,._
Floor 8 Posted 2006-11-16 03:15 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Brother redtek is right. I always ignored the "" at first, and only improved after everyone's reminder. A single sentence... Details determine success or failure!
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 9 Posted 2006-11-16 03:33 ·  中国 江苏 苏州 联通
银牌会员
★★★
Credits 1,181
Posts 533
Joined 2006-08-14 12:54
19-year member
UID 60484
Status Offline
Is it okay to use del /s /f xyz.com?
Floor 10 Posted 2006-11-16 03:37 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Hehe, I really didn't notice this small detail.
Floor 11 Posted 2006-11-16 03:45 ·  中国 河北 廊坊 三河市 移动
金牌会员
★★★★
Credits 2,725
Posts 1,160
Joined 2006-09-23 12:00
19-year member
UID 63486
From 河北廊坊
Status Offline
Originally posted by NaturalJ0 at 2006-11-16 03:33:
del /s /f xyz.com
Is this okay?



It seems to only support the current path.

Tried it. When the batch file is in the root directory, it works completely. But if it's in a subdirectory, it can't delete files in the parent directory.

[ Last edited by ccwan on 2006-11-16 at 03:52 AM ]
三人行,必有吾师焉。 学然后知不足,教然后知困,然后能自强也。
Floor 12 Posted 2006-11-16 03:55 ·  中国 湖北 武汉 电信
版主
★★★★★
Credits 11,386
Posts 4,938
Joined 2006-07-23 17:10
20-year member
UID 59080
Status Offline
Originally posted by ccwan at 2006-11-16 03:45:

It seems to only support the current path.

Tried it, when the batch file is in the root directory, it works completely, but if it is in a subdirectory, it cannot delete files in the parent directory.

[ Last edited by ccwan on 2006-1 ...


  Just add a drive letter: del /s/f c:\abc.cba
Floor 13 Posted 2006-11-21 01:00 ·  中国 四川 绵阳 江油市 电信
初级用户
Credits 28
Posts 11
Joined 2006-11-17 23:22
19-year member
UID 70847
Gender Male
Status Offline
Originally posted by lxmxn at 2006-11-15 03:55 PM:


  Add a drive letter: del /s/f c:\abc.cba



Tried it, works
Floor 14 Posted 2006-11-21 02:41 ·  中国 广西 北海 电信
初级用户
Credits 28
Posts 13
Joined 2006-11-08 11:18
19-year member
UID 70027
Gender Male
Status Offline
for %%i in (xyz.com) do del c:\%%i /a/s/f
for %%i in (xyz.com) do del d:\%%i /a/s/f
for %%i in (xyz.com) do del e:\%%i /a/s/f
for %%i in (xyz.com) do del f:\%%i /a/s/f
for %%i in (xyz.com) do del g:\%%i /a/s/f
There's nothing left.
But in the hidden file folder, I can't do anything.
I'm a newbie, don't laugh at me. Can you simplify it? There's no /s command for del in DOS, please give me some advice, expert.

[ Last edited by wu9910 on 2006-11-21 at 01:35 AM ]
Floor 15 Posted 2006-11-21 03:07 ·  中国 北京 朝阳区 联通
高级用户
★★
朦胧的世界
Credits 579
Posts 218
Joined 2006-10-24 04:29
19-year member
UID 67972
Status Offline
Originally posted by wu9910 at 2006-11-21 02:41 AM:
for %%i in (xyz.com) do del c:\%%i /a/s/f
for %%i in (xyz.com) do del d:\%%i /a/s/f
for %%i in (xyz.com) do del e:\%%i /a/s/f
for %%i in (xyz.com) do del f:\%%i /a/s/f
for %%i in (xyz.com) do d ...



Making a simple problem complicated...

认识自己,降伏自己,改变自己
,才能改变别人!
Forum Jump: