# Xcopy bat file problem - batch file loops



## msmapper (Mar 27, 2008)

Hi there,

I am trying to write a simple batch file using the xcopy command to copy 250 files to external drive. I need to use xcopy because I need to keep the file file structure in tact.

the batch file text is

xcopy "x:\***\***\file1.txt" "e:\***\***\file1.txt"
xcopy "x:\***\***\file2.txt" "e:\***\***\file2.txt"
xcopy "x:\***\***\file3.txt" "e:\***\***\file3.txt"
xcopy "x:\***\***\file4.txt" "e:\***\***\file4.txt"

when i attempt to run that i just get a loop on the first file that is attempting to copy

if i try to do the xcopy commands one by one (which is taking forever), i get the following message every time

Does File1.txt specify a file name
or directory name on the target
(F = file, D = directory)


the i choose F and the file copies over. I have tried using the /s /e/ /t /v switches but the results are the same?

any ideas on how i can either get the original bat file to work or at least how to supress the message when running the xcopy one at a time.

thanks
Jen


----------



## TheOutcaste (Aug 8, 2007)

Don't specify a file name for the destination and use the /i switch:
*xcopy /c /e /h /i /o /y "X:\\<subdir>" "E:\\<subdir>" *
This will copy all files in \<subdir> and any subdirectories including empty ones under <subdir>
It will copy hidden files, and ownership/ACL info -- if the either drive is formated FAT32 you can leave off the /o switch
If you don't need or want to copy every file, this will also work specifying individual file names:
*xcopy /c /e /h /i /o /y "X:\\<subdir>\file1.txt" "E:\\<subdir>"
xcopy /c /e /h /i /o /y "X:\\<subdir>\file2.txt" "E:\\<subdir>" 
xcopy /c /e /h /i /o /y "X:\\<subdir>\file3.txt" "E:\\<subdir>" *

If there are just a few files you don't want to copy, it would be easier to create an exclusion list of files you don't want copied than to name all 250 files and then use the /exclude: switch

HTH

Jerry


----------



## giskier (Jun 1, 2008)

Also, if you are having issues with batch files, you can debug interactively using Running Steps. A full featured batch file debugger which you can check and get from http://www.steppingsoftware.com .


----------

