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?
 
Farhan KaziConnect With a Mentor Systems 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
 
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
Cloud Class® Course: Certified Penetration Testing

This CPTE Certified Penetration Testing Engineer course covers everything you need to know about becoming a Certified Penetration Testing Engineer. Career Path: Professional roles include Ethical Hackers, Security Consultants, System Administrators, and Chief Security Officers.

 
andyw27Author Commented:
Date /T

13/04/2010

ECHO %DATE%

13/04/2010
0
 
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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.