What I’d like to do is self-delete my file following its execution, which involves a script exiting out of cmd. Is there a way to line up a .bat, which will be in an unknown directory, to be marked for deletion following the closing of .cmd, so that it doesn’t mess up my code?
The code I’m using right now just to find the path I need is
dir /B /S filename.bat
If I try to set it as a variable,
set var=dir /B /S filename.bat
del %var%
the return message I receive is that “B” is an invalid switch. This is going to (hopefully) be implemented remotely on Windows 7 machines on a large scale (read: imaging). On top of that, the code above would delete in the middle of implementation, leading to killing the program. I’m looking at, perhaps, logging the response and then printing that to the var, but I’m new to this and I’m pretty much stuck on how to cause the delete command to execute after cmd closes. I’m open to better/more efficient suggestions than what I have for finding/deleting the file.
Insert this line in your Batch file:
previous line delete the running Batch file and exit out of cmd.exe