Trying to use Move vs. Xcopy in a batch file

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Snake Eyes
Posts: 2
Joined: 01 Feb 2011 15:08

Trying to use Move vs. Xcopy in a batch file

#1 Post by Snake Eyes » 01 Feb 2011 15:16

Greetings All.
I have the following batch file that returns the error
"The syntax of the command is incorrect."

Code: Select all

 
@echo off
cls
setlocal enabledelayedexpansion

set /a rand=%random%%%176+1

pushd M:\Wallpapers 1
 
set nbr=1
for /f "delims=*" %%1 in ('dir /a-d /b *.jpg') do (
    set file=%%1
    set /a nbr+=1
    if !nbr! gtr !rand! goto getout
)

:getout
move "%file%" "M:\Test\*.*" /y


If I replace the "move" with "Xcopy" the batch runs with no issue. The file is copied.

I need to move the random file instead of copy it. What do I have wrong?

Kindest Regards,
Snake Eyes

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Trying to use Move vs. Xcopy in a batch file

#2 Post by aGerman » 01 Feb 2011 15:35

Never use a number as FOR-variable. Use e.g. %%a instead of %%1.
Untested:

Code: Select all

@echo off
setlocal enabledelayedexpansion

set /a rand=%random%%%176+1

pushd "M:\Wallpapers 1"

set /a nbr=1
for /f "delims=" %%a in ('dir /a-d /b *.jpg') do (
    set "file=%%a"
    set /a nbr+=1
    if !nbr! gtr !rand! goto getout
)

:getout
move "%file%" "M:\Test\"

popd


Regards
aGerman

Snake Eyes
Posts: 2
Joined: 01 Feb 2011 15:08

Re: Trying to use Move vs. Xcopy in a batch file

#3 Post by Snake Eyes » 01 Feb 2011 15:40

Thanks for the help aGerman.
That Got it.

Snake Eyes

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Trying to use Move vs. Xcopy in a batch file

#4 Post by aGerman » 01 Feb 2011 15:53

Haha, sorry I haven't pointed the main problem. You didn't see it in my code: there is no *.* :wink:
Have a look at all the small changes I did.

Regards
aGerman

<EDIT: OK you found it by yourself :) />

Post Reply