PDA

View Full Version : xcopy batch script - invalid number of parameters



jaketrsw
21-04-2010, 09:26 AM
I've got a batch script that I want to use to copy a bunch of files from a list.txt doc into another location.
The script returns the 'invalid number of parameters' error message and doesn't copy any files.
I think its something to do with having spaces in the file names but I can't get around this problem despite trying all manner of quotations etc..

Here is the script:

@echo off & setlocal
:first, make sure the dest directory exists!
md H:\My Documents\Newest_Duplicates 2>nul
cd c:\
for /f "delims=" %%a in (H:\duplicateslist.txt) do (
xcopy "%%a" "H:\My Documents\Newest_Duplicates" /Y
)
Pause

and here is a sample of the duplicateslist.txt doc

"H:\My Documents\Policy Doc Reorganisation\Policy Documents\Intranet P&P Docs\Professional Practice\-+couple+counselling+framework.pdf"
"H:\My Documents\Policy Doc Reorganisation\Policy Documents\NO P&P Docs\Professional Policies\FC Policy\04 FC Guidelines - v1"
"H:\My Documents\Policy Doc Reorganisation\Policy Documents\NO P&P Docs\Professional Policies\FC Policy\04 FC Guidlines - v2"
"H:\My Documents\Policy Doc Reorganisation\Policy Documents\NO P&P Docs\Professional Policies\FC Policy\04-04 FC Guideleines"

Can anyone see a problem with my script?

inphinity
21-04-2010, 10:01 AM
"delims="
You'v used the delimetered specify flag and not specified a delimeter. I presume you want to use new line? The default is space iirc.

jaketrsw
21-04-2010, 10:11 AM
"delims="
You'v used the delimetered specify flag and not specified a delimeter. I presume you want to use new line? The default is space iirc.

Thanks,
I'm not sure what that means because I got that particular bit of the code off a forum that suggested that it would remove the spaces in filenames problem. It didn't, but I also didn't take it out since it wasn't hurting either.
So what syntax would you suggest I use to have the delims remove the spaces problem?

inphinity
21-04-2010, 10:20 AM
the delimeter flag specifies what character(s) to use to determine where each wanted variable in the file starts and ends, so in your case, if you have a folder listed per line, you will want to use the new line character as your delimeter.

You may also require a trailing backslash on the folder names, and - depending on which version of xcopy, those paths may simply be too long.

fred_fish
21-04-2010, 11:01 AM
@echo off & setlocal
::first, make sure the dest directory exists! ## one colon is a label
md "H:\My Documents\Newest_Duplicates" 2>nul ##quotes required for space
cd c:\
for /f "delims=" %%a in (H:\duplicateslist.txt) do (
xcopy %%a "H:\My Documents\Newest_Duplicates" /Y ## extra quotes not required
)
Pause


Can anyone see a problem with my script?
seems to work ok

jaketrsw
21-04-2010, 11:15 AM
Ok - I feel like a bit of an idiot...
I had quotations around the first %%a in my script but I didn't include them in the version I posted. When I took them out of my batch script it worked fine. Thanks fred_fish - your post alerted me to the discrepancy.
Also thanks inphinity, I now use the new line delimiter switch.

HAL9000
21-04-2010, 12:18 PM
I appreciate that you've spent some time getting xcopy to work but it does have some limitations.

Suggest that you look into robocopy. It was developed by an MS engineer to fix xcopys limitations. I've converted to using it and have not struck the same issues I had with xcopy, namely long directory paths, long file names and so on.