Solved

get delete confirmation

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

863 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

Need Help in Real-Time?

Connect with top rated Experts

27 Experts available now in Live!

Get 1:1 Help Now