2

I'm trying to create a backup batch file, it's been a number of years since I last did one and I'm having a bit of trouble.

I am creating a folder in one location with the date and time in the folder name and copying all folders and files from a set location.

The batch file creates the folder no problem but comes up with 'Invalid number of parameters' on the XCOPY.

The file as it stands is:

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%

set stamp=Backup %DD%.%MM%.%YYYY% %HH%-%min%-%Sec%
set direc="f:\main accounts management\sagecompaniesbackup\%stamp%"
md %direc%
set fold="%direc%"
XCOPY "e:\SageCompanies\" %fold% /c/e/k/y

I've even tried it without any of the parameters on XCOPY but still get the same problem.

I hope someone out there can help me.

1 Answer 1

1

Here's the fix

@echo off
for /f "delims=" %%a in ('wmic OS Get localdatetime  ^| find "."') do set dt=%%a
set datestamp=%dt:~0,8%
set timestamp=%dt:~8,6%
set YYYY=%dt:~0,4%
set MM=%dt:~4,2%
set DD=%dt:~6,2%
set HH=%dt:~8,2%
set Min=%dt:~10,2%
set Sec=%dt:~12,2%

set stamp=Backup %DD%.%MM%.%YYYY% %HH%-%min%-%Sec%
set direc="f:\main accounts management\sagecompaniesbackup\%stamp%"
md %direc%
  ::Removed Double Quotes
    set fold=%direc%
  ::Added Wildcard to fix invalid params
XCOPY "e:\SageCompanies\*" %fold% /c/e/k/y
2
  • Thanks for the help, it worked. I'd put the double quotes in deliberately at one stage as it fixed a previous problem I had however no longer needed and fixed the current error by removing.
    – ShadesUK
    May 13, 2015 at 11:40
  • @ShadesUK, if the answer helped, can you mark it as answer accepted please
    – td512
    May 13, 2015 at 11:43

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .