Monday, July 20, 2009

The folly of Xcopy.exe

Problem: Xcopy.exe prompts me to ask me if what i'm copying is a file or directory?

Tech Details: I have 2 files I wish to copy. 1 file already exists in the destination(and is read only) and the 2nd may or may not exist in that location (pending who was upgraded)

Note: Since file 1 is read only, Copy.exe doesn't like to overwrite read only files

So
Xcopy c:\1.txt d:\temp\1.txt <-- this will work OK because its overwriting the existing file Xcopy c:\2.txt d:\temp\2.txt <-- doesn't work becuase it prompts the user is what i'm copying a file or a diretcory? (because file2.txt doesn't exist) Even if you put the /Q as an arguement on xcopy.exe it halts. It asks the user but just doesn't show the question... DUH WTF? Anyway the way I get around this is to use Copy.exe and not xcopy.exe. We just have to make sure we prepare the copy area first. I.E REM Prepare the copy area first del /F /Q "c:\temp\1.txt" del /F /Q "c:\temp\2.txt" <--- included for the people whom may have this file. REM Copy the files copy /F /Y c:\1.txt c:\temp1.txt copy /F /Y c:\2.txt c:\temp2.txt

This works for me and may be useful for others.

then of course there is Robocopy

No comments :

Post a Comment