Batch File XCOPY Invalid number of parameters

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.

ShadesUK

Posted 2015-05-13T10:17:40.767

Reputation: 21

Answers

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

td512

Posted 2015-05-13T10:17:40.767

Reputation: 4 778

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 – 2015-05-13T11:40:50.843

@ShadesUK, if the answer helped, can you mark it as answer accepted please – td512 – 2015-05-13T11:43:25.410