Question:
Will moving a running batch file stop it?
Janet
2012-03-13 10:48:35 UTC
I am a writing a batch file.

Halfway through the code, I am going to make the batch file move itself into another directory.

Will this stop the batch file from continuing to run?

Thanks for any help
Four answers:
Nunya
2012-03-13 11:00:17 UTC
if you try to move the batch file, or any file really, while its in use, you will get an error.
Jake
2012-03-13 11:16:48 UTC
At whatever point the batch file is moved, it will display an error and the batch file will cease at that moment. Might I suggest first copying the file, and then at the end of the batch file, delete itself using this command:



start /b del "%~nx0">nul



the start /b means that it will open another command in the same window. Without this, you will get an error message.

the del "%~nx0" is the exact same thing as typing DEL, and then your batch file's filename all out. Only this way, if you change your batch file's filename, you won't have to change it inside of the DEL command. it will do it for you.

the >nul means it won't display anything on the screen - otherwise you'll get two command prompts showing. *awkward*
William K
2012-03-13 10:52:22 UTC
Hi,

the code will error when you get to the move instruction.



why not??

make a copy of the batch file and then move that !!!!!!



hope this helps you
?
2016-11-09 03:21:06 UTC
are you speaking of a classic nightly procedure or a one time batch flow? DOS/CMD information ought to get replaced with PowerShell or cygwin bash the position conceivable. in my opinion i exploit cygwin bash on Windozes packing containers, it truly is a lot extra elementary to script with I create for or do at the same time as loops that list the document in a listing previous to processing then carry out the technique of flow, replica, or push. with a bash shell script, it it really basic cd DIRNAME for document in `ls` do mv $document to call$document. finished the above will flow document and append call to the front of document call. CMD has a tendency in the route of a very antiquate syntax, and analyzing in from STDIN/STDOUT is complicated at maximum ideal. microslop more advantageous issues fairly with the introduction of powershell, yet you need to could be on XPSP3 or newer to get it. One social gathering i found seek for some developer information superhighway sites shows one social gathering. $basepath = 'C:DropboxMy Dropboxscriptstest' $targetpath = 'C:DropboxMy Dropboxscriptstest2' dir -Recurse $basepath |?{!($_.psiscontainer)}|% { $newlocation = $_.fullname -replace ($basepath -replace '',''), $targetpath if (!(attempt-route (chop up-route $newlocation))) { md (chop up-route $newlocation) } replica $_.fullname -destination $newlocation } My rec is to apply cygwin, scripting in a Unix form shell is elementary as shown in my 1st social gathering. cygwin, is for sale and could run properly on Windozes pcs from ninety 5 to Windoze 7, and from NT4 to Server 2008R2.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...