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-06-21 09:39
中国DOS联盟论坛 » DOS批处理 & 脚本技术(批处理室) » Echo output of the del command View 739 Replies 2
Original Poster Posted 2009-09-06 06:09 ·  中国 上海 浦东新区 电信
新手上路
Credits 7
Posts 6
Joined 2009-08-20 13:48
16-year member
UID 150693
Gender Male
Status Offline
When executing the del delete command, if it succeeds there is no echo output at all; if it fails there will be prompts like file does not exist, etc.
Now I want a prompt after success so it can be distinguished from other cases.
I tried the parameters of del and none of them can do it. Only the /s parameter gives a prompt when deleting a single file, but /s will recursively delete files with the same name in subdirectories, so it isn't safe.
Are there any other delete commands that have this function?

I wrote an echo %errorlevel% command that can show whether the deletion succeeded (actually using dir filename to see whether it still exists), but if I write it on separate lines in a bat it works, while if I write it on one line it may not work because of the & syntax. Please help me see what the problem is:

Successful two-line script:

del t.txt 
@echo off&dir t.txt>nul 2>&1
echo %errorlevel% &@echo on


Unsuccessful one-line script:
del t.txt 
@echo off&dir t.txt>nul 2>&1 &echo %errorlevel% &@echo on
Floor 2 Posted 2009-09-06 06:15 ·  中国 广东 广州 电信
银牌会员
★★★★
SuperCleaner
Credits 2,362
Posts 1,133
Joined 2008-02-02 21:36
18-year member
UID 110072
Gender Male
Status Offline
The so-called compound thing, because it's in the same statement~
This was discussed before, I forgot the reason.
If it's on the same line, using enabled variable expansion !! should work


del t.txt
@echo off&setlocal enabledelayedexpansion &dir t.txt>nul 2>nul &echo !errorlevel! &@echo on


And there's another way:

del t.txt
@echo off &(dir t.txt>nul 2>nul&&echo 0)||(echo 1)


[ Last edited by 523066680 on 2009-9-6 at 06:22 ]
Floor 3 Posted 2009-09-06 07:27 ·  中国 江西 赣州 电信
银牌会员
★★★★
Credits 2,025
Posts 1,122
Joined 2007-09-05 20:15
18-year member
UID 96653
Gender Male
Status Offline
When should delayed expansion be used?
http://www.cn-dos.net/forum/viewthread.php?tid=20733
Forum Jump: