0

I get "File Creation Error" when I use xcopy to move a file to a path. This code works fine:

for /f "eol=: delims=" %%a in (D:\Scripts\filelist.txt) do (
   for /f "eol=_ tokens=4 delims=-" %%b in ("%%a") do (    
      xcopy /I /K /Q /R /Y  "E:\ReportOutput\IAP_ddz\%%a" "E:\ReportOutput\IAP_ddz\BySchool\%%b\test\" >> Output.txt
   )
)

But when I make a simply change to the xcopy statement shown below, it gives a "File Creation Error - The system cannot find the path specified".

xcopy /I /K /Q /R /Y  "E:\ReportOutput\IAP_ddz\%%a" "E:\ReportOutput\IAP_ddz\BySchool\%%b\test\" >> Output.txt.

I am using Windows Server 2008 R2 Standard & I run CMD as Administrator.

MadsTheMan
  • 705
  • 1
  • 10
  • 32
Durand
  • 1
  • 1
  • 2
    Was the change just appending the final period to the Output.txt file? I think the issue may be that Windows Command Prompt doesn't like to work with files that end with period. Periods precede a file extension, but not giving it one makes it error, I think. But, if that wasn't the change, I couldn't spot it. What was the actual desired change? – yftse Jan 25 '16 at 01:08
  • There must be more to the story. I cannot reproduce that error. @yftse - It is true that Windows does not allow trailing dots or spaces in file/folder names. But Windows will strip any trailing dots or spaces from a file name, so the redirection works fine with the trailing dot, at least in my hands. – dbenham Jan 25 '16 at 14:52
  • so, strange, the error went away for now? for some reason, i had expected that you might have changed the path where the file would be copied to yield that type of error. I visually compared the your code blocks, but couldn't spot the differences. When the issue would manifest again, i would check the existence of all the paths. good luck. – yftse Jan 25 '16 at 15:20
  • Apologies to yttse & dbenham for taking up your time. The code that works doesn't have "test" in the destination path. The dot in the code that doesn't work shouldn't be there. To summarise, the code that works is: "xcopy /I /K /Q /R /Y "E:\ReportOutput\IAP_ddz\%%a" "E:\ReportOutput\IAP_ddz\BySchool\%%b\" >> Output.txt" (no "test") and the code that doesn't work is "xcopy /I /K /Q /R /Y "E:\ReportOutput\IAP_ddz\%%a" "E:\ReportOutput\IAP_ddz\BySchool\%%b\test\" >> Output.txt" – Durand Jan 26 '16 at 21:48
  • I just noticed %%b has a trailing space before "\test\". When I removed the trailing space from %%b it worked. Eg of %%b is "School of Medicine ". Easier to get the report generation program to remove the space instead of another loop to remove it since BAT doesn't have a Length or Trim function. Thanks for your suggestions. It was a catalyst for finding the problem. Next time I will post the source data as well. – Durand Jan 26 '16 at 22:15

0 Answers0