I am trying to copy a set of files to a new location that I have listed out in a file list (filelist.txt) by using a for loop and xcopy command. However, there is an issue with my script where a directory with an identical file name is being created.
So for instance, I have the following within filelist.txt
MC\1807\1807-06-10\M-1807-00246071.tif
BC\1825\18250218\B-1825-00000012-0.tif
BC\1837\18370727\B-1837-00000013-0.tif
MC\1848\1848-08-04\M-1848-00000007.tif
MC\1849\1849-02-24\M-1849-00000008.tif
The command line execution looks like this:
for /f "delims=" %i in (filelist.txt) do echo D|xcopy "E:\files\%i" "F:\files\%i" /i /z /y
Notice I am copying from E to F drives. So on E, the files are stored as such:
E:\files\MC\1807\1807-06-10\M-1807-00246071.tif
E:\files\BC\1825\18250218\B-1825-00000012-0.tif
E:\files\BC\1837\18370727\B-1837-00000013-0.tif
E:\files\MC\1848\1848-08-04\M-1848-00000007.tif
E:\files\MC\1849\1849-02-24\M-1849-00000008.tif
After I run the xcopy command, I receive this result set:
F:\files\MC\1807\1807-06-10\M-1849-00000008.tif\M-1807-00246071.tif
F:\files\BC\1825\18250218\M-1849-00000008.tif\B-1825-00000012-0.tif
F:\files\BC\1837\18370727\M-1849-00000008.tif\B-1837-00000013-0.tif
F:\files\MC\1848\1848-08-04\M-1849-00000008.tif\M-1848-00000007.tif
F:\files\MC\1849\1849-02-24\M-1849-00000008.tif\M-1849-00000008.tif
Notice how it created a folder with the files names and then placed the file within that folder instead of a direct copy from the source directory to the destination directory.
What is it within my xcopy command that could cause for this?
I figured it out. When doing the copy, it prompts you whether it is a Directory (D) or a File (F). On my echo, I was returning D:
for /f "delims=" %i in (filelist.txt) do echo D|xcopy "E:\files\%i" "F:\files\%i" /i /z /y
By changing it to echo F, this has been resolved.
for /f "delims=" %i in (filelist.txt) do echo F|xcopy "E:\files\%i" "F:\files\%i" /i /z /y