Using xcopy with folders with spaces

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
jc001
Posts: 5
Joined: 06 Dec 2018 12:09

Using xcopy with folders with spaces

#1 Post by jc001 » 15 Dec 2018 12:08

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?

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Using xcopy with folders with spaces

#2 Post by aGerman » 16 Dec 2018 07:04

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

jc001
Posts: 5
Joined: 06 Dec 2018 12:09

Re: Using xcopy with folders with spaces

#3 Post by jc001 » 16 Dec 2018 12:22

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

Post Reply