Solved

get delete confirmation

Posted on 2007-12-05
4
477 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

3 Use Cases for Connected Systems

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, testing some more, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us.

Question has a verified solution.

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

Being a system administrator some time we require to do things remotely, one of them is installing software. Here I am going to tell you how to install software through wmic (Windows management instrument console). I am not at all saying that this i…
Use this article to create a batch file to backup a Microsoft SQL Server database to a Windows folder.  The folder can be on the local hard drive or on a network share.  This batch file will query the SQL server to get the current date & time and wi…
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

773 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