Xcopy - Invalid Number of Parameters Error

Hi,

I have simple batch file that copy files from one location to another.  Yesterday afternoon it worked, this morning it does'nt, gives the "Invalid number of parameters" error message.

I'm pretty confident the error lies within this line of code:

SET dateNtime="%date:~0,2%-%date:~3,2%-%date:~6,6%_%time:~0,2%-%time:~3,2%"

As if I remove it the code works.  Could it be that yesterday the time was afternoon so it displayed 15:42, but this morning there is a space as it's  8:40 ?

Any suggestions appreciated

Here is all the code

@echo off
:: variables
set drive=F:\Backup\
SET dateNtime="%date:~0,2%-%date:~3,2%-%date:~6,6%_%time:~0,2%-%time:~3,2%"
set backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up the directory...
%backupcmd% "\\network1\folder1\*.*" "%drive%\%dateNtime%"

echo Backup Complete - Your Backup is located at %drive%
@pause

Open in new window

andyw27Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Farhan KaziSystems EngineerCommented:
Can you please post the output of following:

Click Start -> Run -> Cmd.exe -> OK

DATE /T
or
ECHO %DATE%
0
jakethecatukCommented:
Suggest you split dateNtime into two fields.

You can then use "%drive$\%var_date%%var_time%" and you will not have any spaces.
0
andyw27Author Commented:
Date /T

13/04/2010

ECHO %DATE%

13/04/2010
0
Why Diversity in Tech Matters

Kesha Williams, certified professional and software developer, explores the imbalance of diversity in the world of technology -- especially when it comes to hiring women. She showcases ways she's making a difference through the Colors of STEM program.

Farhan KaziSystems EngineerCommented:
Check if this works for you!
@ECHO OFF
set drive=F:\Backup\

For /f "tokens=1-3 delims=/ " %%a in ('date /t') do (set mydate=%%a-%%b-%%c)
For /f "tokens=1-2 delims=/: " %%a in ('time /t') do (set mytime=%%a%%b)

:: variables
SET dateNtime=%mydate%_%mytime%
SET backupcmd=xcopy /s /c /d /e /h /i /r /k /y

echo ### Backing up the directory...
%backupcmd% "\\network1\folder1\*.*" "%drive%\%dateNtime%"

echo Backup Complete - Your Backup is located at %drive%
@pause

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Steve KnightIT ConsultancyCommented:
I suggedt you use my date code from here:

http://www.experts-exchange.com/articles/OS/Microsoft_Operating_Systems/MS_DOS/Using-dates-in-batch-files-scripts.html

It avoids all problems with leading zeoes etc.  Either that or remove spaces from the name or put quotes around it:

If you can live with the spaces instead of leading zeroes then remove the quotes here:

SET dateNtime=%date:~0,2%-%date:~3,2%-%date:~6,6%_%time:~0,2%-%time:~3,2%

as you already quote on the xcopy line too.

If you want to remove the spaces try:

SET dateNtime=%date:~0,2%-%date:~3,2%-%date:~6,6%_%time:~0,2%-%time:~3,2%
set datetime=%datetime: =%

Steve
0
Steve KnightIT ConsultancyCommented:
That last bit should be

set dateNtime=%dateNtime: =%

It just replaces space with nothing.

Would seriously suggest looking at the article of mine though as it will work then regardless of the users dae and time settings etc.

Sorry for an typos, typing one handed with baby asleep on shoulder!
0
Steve KnightIT ConsultancyCommented:
Thanks to you too.
Steve
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Windows Batch

From novice to tech pro — start learning today.