My question is: how can I get a batch file to delete itself? I tried "del /f", but to no avail. I was thinking maybe I could get it to "move" itself to the trash can, but how would I do this? (what is the trash can's file location?)
Batch file help
Started by
stettybet0
, Apr 11 2007 04:00 PM
#1
Posted 11 April 2007 - 04:00 PM
My question is: how can I get a batch file to delete itself? I tried "del /f", but to no avail. I was thinking maybe I could get it to "move" itself to the trash can, but how would I do this? (what is the trash can's file location?)
#2
Posted 11 April 2007 - 04:48 PM
Not possible AFAIK. Would have been under old DOS, but XP won't let you delete something its using itself. This could also include batch files.
#3
Posted 11 April 2007 - 04:51 PM
no chance even by using my "move" to trash can theory? I know a file can move itself... so why not to the trash can? I just don't know how to reference the trash can.
#4
Posted 11 April 2007 - 05:35 PM
To test this create a folder and place a text file within it. I made a new folder in C:\ named Test. I then created a text file in Notepad named test.txt. I used the following batch file (test.bat) to remove the text file from the folder then delete the batch file itself.
del C:\Test\test.txt del test.bat
#5
Posted 11 April 2007 - 07:56 PM
umm... im not sure what the text file thing was for... but del .\test.bat works... But why wasn't it working before??? Hmm... the only thing I can think of is that right before I have the file delete itself, I have it run shutdown -r -t 0. So, it begins the restart process immediately. I would think it would be able to delete the file while shutting down, but maybe not... but I need the file to initialize a restart... how can I make it do that and delete itself?!? I tried adding more time before the restart process started, but that didn't help.
#6
Posted 12 April 2007 - 03:04 PM
Following my same setup.
The only reason I use C:\Test\test.txt is because I constantly use the Test folder for testing purposes. No sense in continually recreating it. This way only the file located within it gets deleted.
shutdown /f /r del C:\Test\test.txt del test.bat
The only reason I use C:\Test\test.txt is because I constantly use the Test folder for testing purposes. No sense in continually recreating it. This way only the file located within it gets deleted.
#7
Posted 12 April 2007 - 03:08 PM
when you initiate the shutdown command with the /f command it FORCES anything else running to terminate..therefor as soon as you hit the line shutdwon /f /s it terminates the batch file
why are you trying to delete a batch file as soon as it runs?
why are you trying to delete a batch file as soon as it runs?
#8
Posted 12 April 2007 - 04:46 PM
Im using it as part of the installation process for a program of mine to automatically install an included font file. However, once the person runs it, they have no reason to run it again, and it would have errors (the font file to install would no longer be there!) So I want it to delete itself. I need it to restart, because newly installed fonts don't always work immediately unless a restart occurs.
I could write a second batch file that deletes the original one and itself and make a registry file that lets it run on startup, but I really don't want to (more trouble than its worth).
I could write a second batch file that deletes the original one and itself and make a registry file that lets it run on startup, but I really don't want to (more trouble than its worth).
#9
Posted 13 April 2007 - 06:26 AM
well...theoretically...you could have the installer create the second batch that would delete the first and itself in the startup folder...that way as soon as the PC restarts they both get deleted....you could also have it pop up a message box that says "you must restart your computer" and have it delete itself but NOT force the restart
Similar Topics
0 user(s) are reading this topic
0 members, 0 guests, 0 anonymous users