Computing.Net > Forums > Disk Operating System > Batch File

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Click here to start participating now! Also, check out the New User Guide.

Batch File

Reply to Message Icon

Name: NY
Date: August 6, 2002 at 16:31:10 Pacific
Comment:

Is it possible to create a self destructive batch file or even automatically delete all the contents from that batch file after the batch file has finished its job.
Any help would be appreciated.



Sponsored Link
Ads by Google

Response Number 1
Name: Troy
Date: August 6, 2002 at 17:27:38 Pacific
Reply:

You can put del at the end of your batch file. It will say that the file is missing, but it will still delete it. Anything after the delete will not be processed.


0

Response Number 2
Name: Troy
Date: August 6, 2002 at 17:28:30 Pacific
Reply:

Sorry, be sure to include the file name of your batch file right after del.


0

Response Number 3
Name: NY
Date: August 6, 2002 at 18:07:57 Pacific
Reply:

It worked. Thank You.


0

Response Number 4
Name: Secret_Doom
Date: August 7, 2002 at 12:49:16 Pacific
Reply:

There's a way to make a batch file self-delete without that message comming up:

@echo off
echo Main batch goes here!
echo %0? |FIND/i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
del %THIS%[eof]

[eof] is reperesenting the END-OF-FILE character, which you can get on EDIT.COM by pressing CTRL+P+Z.

Everything after the [eof] is ignored, so if in your batch file you need to exit without self-deleting it, this will NOT work:

@echo off
echo We will exit without self-deleting
goto end
echo %0? |FIND/i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
del %THIS%[eof]
:end

In order to be able to exit the batch file without self-deleting it, use this:

@echo off
type nul> %TEMP%.\batexit.bat
echo We will exit without self-deleting
%TEMP%.\batexit.bat
echo %0? |FIND/i ".bat?" > nul
if not errorlevel=1 set THIS=%0
if errorlevel=1 set THIS=%0.BAT
del %THIS%[eof]

Got it?

This information was extracted from Laurcence Soucy's batch FAQ #2.
http://home7.inet.tele.dk/batfiles/

-- Leonardo Pignataro - Secret_Doom --

secret_doom@hotmail.com
www.batch.hpg.com.br


0

Sponsored Link
Ads by Google
Reply to Message Icon

Related Posts

See More


USB Mouse DOS won't read any other ...



Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Disk Operating System Forum Home


Sponsored links

Ads by Google


Results for: Batch File

Help!! Batch File www.computing.net/answers/dos/help-batch-file/13525.html

Batch files - - Mapping network drive www.computing.net/answers/dos/batch-files-mapping-network-drive/3809.html

Pause batch file www.computing.net/answers/dos/pause-batch-file/2810.html