Why does xcopy not copy files when using these parameters?
Solution 1
Well, that's annoying; I found the issue. It looks like when I generated my CSV file, it put a space at the end of each line, so xcopy was looking for files that had a space after the extension.
The thing that was throwing me off was that it was finding the files, but couldn't copy them, making me think it was a network or xcopy issue.
I just ran a sed script to remove the eol spaces and the xcopy script is now working as expected.
Solution 2
xcopy will also report 0 File(s) copied
if you use forward slashes "/" in paths instead of backslashes "\", though ONLY if you've enclosed the path in quotes.
This fails with "0 File(s) copied"
xcopy "pathname1/file" pathname2\file
This fails with "Invalid number of parameters"
xcopy pathname1/file pathname2\file
This works just fine
xcopy pathname1\file pathname2\file
Solution 3
It asks because it doesn't know whether you want to copy to directory (to be created) or you provide the full target pathname. This will ask:
xcopy pathname1\file.from pathname2\file.to
However, adding slash will tell that you copy to directory:
xcopy pathname1\file.from pathname2\to\
But I haven't found the way to tell explicitly that I want to copy and rename file, except
echo Y | xcopy pathname1\file.from pathname2\file.to
I played a bit with your case (with for, do and xcopy) and found out that even if it asks Does SOMEFILE specify a file name or directory name on the target (F = file, D = directory)? it is provided with f from echo and it's copied successfully. Thus, it's not a problem with file/directory specifying, but with copying through network itself.
Saggio
I am a Microsoft Certified Professional Developer (MCPD) Windows Developer 4, Enterprise Application Developer currently working as a Senior Software Developer in the Medical Imaging Trials industry. #SOreadytohelp
Updated on April 19, 2020Comments
-
Saggio about 4 years
I have a simple xcopy script that I'm running from the command line that reads a CSV file of directories and file names. I've used a very similar script with no problems before. Here is the script:
Z:\HOME\>for /f "delims=, tokens=1,2,3,4" %i in (Z:\HOME\MissingImages.csv) do echo f | xcopy "Y:\%j\%k\%l" "C:\Horizon\%j\%k\%l" >> Z:\HOME\MissingImagesLog.txt
However, it is not copying any of the files over Here is an entry from the log file:
Does C:\Horizon\K\00\6bef500f.IMG specify a file name or directory name on the target (F = file, D = directory)? f 0 File(s) copied
It's finding the images because if I change the root directory to something else the script will just populate the log file with
0 File(s) copied
for all entries, so the files are there and can be seen...Also, the
Z:\
drive is on a network and not local, but again I have used a very similar script across a network without problems (it just takes longer).I've tried different options like
/i
,/s
, etc. but I can't seem to get it to copy any files over.