To Temple College Class  logo R. Craig Collins > ITSC 1305 > %1 and %2, key to MOVE

%1 and %2, key to MOVE © R. Craig Collins, 2007

If you have a file named a:\folder1\junk.txt, and you want to move it to a:\folder2, you could use the MOVE command.

Syntax MOVE [drive:\][directoryname\]filename.ext [drive:\][directoryname\]filename.ext
or simplifies as
MOVE source destination

Before the MOVE command was created, people would have to
1) COPY the file from the source location to the destination location, and then
2) DEL the original file.

Then, people started to capture these step so they could reuse this series of commands, and created a batch file to do this.

The trick is, how do you tell the batch file the name of a file for the source and destination?
Example for first attempt to create a batch file to MOVE files:

COPY a:\folder1\junk.txt a:\folder1\junk.txt
DEL a:\folder1\junk.txt

This batch file would only work one time, you could not reuse it to later move a file named stuff.txt to C:\, for example.

The solution
What DOS came up with was a placeholder that you could code into the batch file that basically said
"The user will provide a filename when the command is used".

Actually, this makes sense. You can't just type COPY, hit the enter key, and expect it to work.
If you just type COPY and hit the enter key, DOS tells you it was expecting a filename (source).
If you just type COPY filename and hit the enter key, DOS tells you it was expecting a filename (destination).

What is used in DOS is %1 to act as a place holder for the first filename to be entered (source) and
%2 to act as a place holder for the first filename to be entered (destination).

So, we code our batch file to the following:

COPY %1 %2
DEL %1

This batch file will now work for any file names.

Here's how it works
If you have a file named a:\folder1\junk.txt, and you want to move it to a:\folder2, you could use the MOV.BAT command

Syntax for MOV    (recall, executable files that end with .exe, .com, or .bat don't require you to include the extension)
MOV  source  destination

Example of MOV   (recall, executable files that end with .exe, .com, or .bat don't require you to include the extension)
MOV  a:\folder1\junk.txt  a:\folder2\junk.txt

What happens

1) DOS grabs the first filename given (the source), a:\folder1\junk.txt, and replaces every %1 with a:\folder1\junk.txt
2) DOS grabs the second filename given (the destination), a:\folder2\junk.txt, and replaces every %2 with a:\folder2\junk.txt
3) DOS executes each line in the batch file, using the replaced filenames

COPY %1 %2 turns into COPY a:\folder1\junk.txt a:\folder2\junk.txt
DEL %1   turns into DEL a:\folder1\junk.txt  

The result is the original file is copied, then that original file is deleted, leaving only the copy... net effect, moving the file.

Note: if you improperly state the destination, the first line of the batch file will not be able to make the copy,
but the second line will still delete the original... leaving you with no file at all.