Page 1 of 1

Trying to use Move vs. Xcopy in a batch file

Posted: 01 Feb 2011 15:16
by Snake Eyes
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

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

Posted: 01 Feb 2011 15:35
by aGerman
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

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

Posted: 01 Feb 2011 15:40
by Snake Eyes
Thanks for the help aGerman.
That Got it.

Snake Eyes

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

Posted: 01 Feb 2011 15:53
by aGerman
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 :) />