5

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.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112
Saggio
  • 2,212
  • 6
  • 33
  • 50

3 Answers3

11

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.

  1. This fails with "0 File(s) copied"

    xcopy "pathname1/file" pathname2\file
    
  2. This fails with "Invalid number of parameters"

    xcopy pathname1/file pathname2\file
    
  3. This works just fine

    xcopy pathname1\file pathname2\file
    
j0k
  • 22,600
  • 28
  • 79
  • 90
iandallas
  • 111
  • 1
  • 3
1

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.

pmod
  • 10,450
  • 1
  • 37
  • 50
  • isn't that the way it's supposed to be, though? Isn't the flow: 1.Xcopy command runs; 2.prompts for file or directory; 3.echo f is executed to complete xcopy command; 4.next xcopy command runs etc. Why would it be problematic for echo f to execute after xcopy? – Saggio Mar 03 '11 at 20:44
  • Updated, it's ok with echo f. How is Z: mapped to system? – pmod Mar 03 '11 at 20:52
  • Found the issue; it was how the csv was created. Thanks for your help! – Saggio Mar 03 '11 at 20:56
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.

Saggio
  • 2,212
  • 6
  • 33
  • 50