Page 1 of 1

Using xcopy with folders with spaces

Posted: 15 Dec 2018 12:08
by jc001
Using xcopy with the code below. I have read you can put double quotes around the source and destination folder so that the folders with spaces can be treated correctly as a directory. However, when I use quotes around the path it shows an error: Invalid number of parameters

Code: Select all

For /D %%K IN ("C:\This Folder") DO xcopy "%%K" "C:\Temp\test\backup001\%%~nK" /D /E /C /R /H /I /K /Y >>C:\Temp\test\backuplogs\backuplog.txt 2>&1
Where should I put the " around to make the above work?

Re: Using xcopy with folders with spaces

Posted: 16 Dec 2018 07:04
by aGerman
You missed the wildcard in your search pattern.

Code: Select all

For /D %%K IN ("C:\This Folder\*") DO ...
Furthermore have a look at option /S of XCOPY. Maybe you don't even need the loop.

Steffen

Re: Using xcopy with folders with spaces

Posted: 16 Dec 2018 12:22
by jc001
Steffen

That's it!! I knew it was something as simple as that.
Changing the line:
For /D %%K IN ("C:\This Folder\*") DO ...
works for me!!
Thank you so much!! :D