Twijn
Twijn

Reputation: 11

Incorrect move syntax?

I cannot figure out how to use the "move" command in batch. Here is what I'm doing:

@ECHO off
SET name=t
SET steam=C:\Program Files (x86)\Steam\steamapps\common\
SET buffer=C:\Users\Tyler\Desktop\buffer\
SET desktop=C:\Users\Tyler\Desktop\
SET s=%steam%%name%
SET b=%buffer%%name%
SET d=%desktop%%name%
ECHO Moving %s% to %buffer%
MOVE %s% %buffer%
ECHO Moving %d% to %steam%
MOVE %d% %steam%
ECHO Moving %b% to %desktop%
MOVE %b% %desktop%
PAUSE

Here is what it says:

Moving C:\Program Files (x86)\Steam\steamapps\common\t to C:\Users\Tyler\Desktop\buffer\
The syntax of the command is incorrect.
Moving C:\Users\Tyler\Desktop\t to C:\Program Files (x86)\Steam\steamapps\common\
The syntax of the command is incorrect.
Moving C:\Users\Tyler\Desktop\buffer\t to C:\Users\Tyler\Desktop\
The system cannot find the file specified.
Press any key to continue . . .

I am trying to move the folder "t" that is in C:\Program Files(x86)\Steam\steamapps\common\t to a "buffer" folder on the desktop. Then, I want to move the folder in the desktop named "t" to the steam path above, then "t" in the buffer folder to "t" in the desktop.

What I will be doing is using this to switch out a game's directory from the modded version to the non-modded version.

Upvotes: 1

Views: 2144

Answers (1)

edo9k
edo9k

Reputation: 135

Your batch script is almost perfect, you only forgot to quote the directory lines. You have to do that because quite often your file and directory names will contain spaces, the interpreter uses these spaces to mark where one argument ends and another begins, therefore you must use double-quote to delimit the arguments.

SET file=moveme.yay
SET from=Z:\home\durden\documents\batch\a with space\
SET to=Z:\home\durden\documents\batch\b with space\
ECHO Moving
move "%from%%file%" "%to%%file%"

If you need to move to more complex scripting while staying on Windows, try PowerShell. (also robocopy1 is a sort of updated version of move and copy, you could use that too)

Thanks for posting this question and bringing me such dos-nostalgia :)

Upvotes: 2

Related Questions