Computing.Net > Forums > Disk Operating System > exporting results from batch file

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

exporting results from batch file

Reply to Message Icon

Name: pure_evil020
Date: April 8, 2009 at 02:39:18 Pacific
OS: Windows XP
CPU/Ram: intel pentium4 1.8 duel core
Subcategory: General
Comment:

Hi there, I am trying to achieve a pretty simple task here, i'm just cant seem to think how to do what i want properly though...

I currently have a batch file that looks like the following:
@echo off
color 91
DEL /F file.exe
DEL /F file.exe
DEL /F file.exe >log.txt

basicly it attempts to delete the same file a few times in a row.
I've tried to make it so it creates a log with the results, but it didnt seem to work...

I would like to have it check for when it has success, then creates a log with the "file has been successfully deleted" message that comes up after it, then have it exit the batch file.

Then If it does not have success by the end of the batch, I want it to create a log with the error.

Is there anyone who has experience in batch file creation that could help me out here?



Sponsored Link
Ads by Google

Response Number 1
Name: IVO
Date: April 8, 2009 at 03:40:47 Pacific
Reply:

You can catch DEL command failure by coding

del File_Name 2>> log.txt

but you can't directly get a log for its success. A workaround is

if exist File_Name (del File_Name & echo. File_Name deleted >> log.txt)

By the way this is NT batch scripting that has nothing to do with DOS (that doesn't exist in XP systems where the kernel is NT based and the prompt operated by cmd.exe not command.com).

0

Response Number 2
Name: pure_evil020
Date: April 8, 2009 at 05:20:38 Pacific
Reply:

hmmmm couldnt you through an "else" variable or something in there after that then?
so it looks something like this:

if exist File_Name (del File_Name & echo. File_Name deleted >> log.txt)
else
echo. File_Name does not exist, or cannot be deleted >> log.txt)


0

Response Number 3
Name: pure_evil020
Date: April 8, 2009 at 05:30:14 Pacific
Reply:

also, could I add onto that code something like this?
if exist test (del test & echo. test deleted & exit>> log.txt)
else (echo. Failure! "test" does not seem to exist, or cannot be deleted. >> log.txt)

is that valid coding?
The reason for putting exit there, is so i can repeat the line of code a second time if it fails.
what do you think?


0

Response Number 4
Name: pure_evil020
Date: April 8, 2009 at 05:54:31 Pacific
Reply:

here is what i've put together so far:

[QUOTE]if exist test (del test & echo. test deleted > log.txt) & exit
else
if exist test (del test & echo. test deleted > log.txt) & exit
else
(echo. Failure! "test" does not seem to exist, or cannot be deleted. >> log.txt)[/QUOTE]

I'm still having a problem with this though...
It is creating two seperate log files. one from the first line, and one from the second.

anyone know why its doing this?


0

Response Number 5
Name: IVO
Date: April 8, 2009 at 06:32:27 Pacific
Reply:

I don't kmow why you want to repeat twice the same command, anyway the general format of the if statement is

if exist File_Name (
  first command
  second command
  ...
) else (
  first command
  second command
  ...
)

i.e. in your example

if exist test (
  del test 2> log.txt
  for %%j in (log.txt) do if %%~zj equ 0 echo. test deleted > log.txt
) else (
  echo. test can't be found > log.txt
)
 

Better you use >> as redirector if you want to add lines to an existing log and for your info 2> means to redirect the standard error messages to a file.

0

Related Posts

See More



Sponsored Link
Ads by Google
Reply to Message Icon





Use following form to reply to current message:

Login or Register to Reply
LoginRegister


Sponsored links

Ads by Google


Results for: exporting results from batch file

MS Access query from batch file www.computing.net/answers/dos/ms-access-query-from-batch-file/2567.html

edit autoexec from batch file www.computing.net/answers/dos/edit-autoexec-from-batch-file/6415.html

Launching browser from batch file www.computing.net/answers/dos/launching-browser-from-batch-file/6555.html