Solved

get delete confirmation

Posted on 2007-12-05
4
479 Views
Last Modified: 2012-08-13
I am piping the output of a batch file to a text file.  one part of my batch file deletes a file and i want that output also to go to the text file.

But when you type in del filename.txt in a command window there is no confirmation that it succeeded.

Is there a flag you can put with the del command so it comes back and says it was successful?
0
Comment
Question by:Fraser_Admin
  • 2
4 Comments
 
LVL 23

Accepted Solution

by:
Ashish Patel earned 500 total points
ID: 20411053
No del command doesnt have anything which says that it was successfull, rather it will give erro if file isnt found or is read only. So, what you do is to trace could not find ..... error after del command is executed and if this message is found then its an error or else everything is good.
0
 

Author Comment

by:Fraser_Admin
ID: 20411090
can you post an example of how I would check if the delete was successful so i can echo my own message if it was.
0
 
LVL 23

Expert Comment

by:Ashish Patel
ID: 20411133
You can find some articals on this on google. I havent tried this, but i know this is the work around.
0
 
LVL 3

Expert Comment

by:yjwong
ID: 20411237
Use the command prompt errorlevels to detect whether an operation is successful. The del command will return 0 (zero) on success, nonzero on failure. Without further ado, here's a sample script (note that I've not tested the script, it may or may not work, but I believe it is a good reference.

Outputs:
File deletion successful!
Failed to delete file!
del myexistentfile.txt
if not %errorlevel% == 0 goto fail:
echo File deletion successful!
 
del mynonexistentfile.txt
if not %errorlevel% == 0 goto fail:
echo File deletion successful!
 
fail:
echo Failed to delete file!

Open in new window

0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of my most closely kept secrets is revealed in this discussion How to output text on the same line This question was recently posted in EE by Simon336697 (http://www.experts-exchange.com/Programming/Languages/Scripting/Shell/Batch/Q_2459…
TOMORROW TOMORROW.BAT is inspired by a question I get asked over and over again; that is, "How can I use batch file commands to obtain tomorrow's date?" The crux of this batch file revolves around the XCOPY command - a technique I discovered w…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…

685 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question