I have a strange problem with xcopy in Windows XP Professional. I don't know if its a stupid question as I am specifying only a file as the source, so should I even expect any other behavior ? This is it:
I am using xcopy <src> <dest> /s/y
.
<src>=C:\sourcefolder\a\b\c\d\something.java
and
<dest>=C:\destinationfolder
.
Now xcopy
copies the file but does not create the directory structure \a\b\c\d\
inside C:\destinationfolder
.
what I want is C:\destinationfolder\a\b\c\d\something.java
and
what I get is C:\destinationfolder\something.java
C:\destinationfolder
by specifying a .
for target folderThere is a script I have which calls xcopy
iteratively so I am left with C:\destinationfolder\many java files
without any directory structure.
A. Yes I have done xcopy /?
to see all options
B. /T
also does not create any empty directory structure
C. I can not go to source folder a\b\c\d\
and run xcopy . <dest>
I removed my previous answer on using ROBOCOPY
. I believe the following will do what you want using XCOPY
.
Assuming your folder structure is like this:
SOURCE = C:\MyJavaStuff\A\B\C\D\something.java
DEST = C:\MyDestination
Run XCOPY
like this:
XCOPY C:\MyJavaStuff\something*.java C:\MyDestination /S /E
Note the *
in something*.java
.
The problem is that you are specifying which file to copy in the source. xcopy won't create the folder structure in this case. However, if you change your call to xcopy to
xcopy *.java C:\myfolder /s/y
it will copy the .java files and the folder structure as well. You need to specify a wildcard for this call to work as you want. If you want only to copy specific files, you will have to adjust the call to xopy, e.g.:
xcopy something.jav* C:\myfolder /s/y
You say that you get the list of files to copy from another command. If you can output this list of files in a text file, you could do the following:
FOR /F "tokens=* delims=," %F in (d:\test\list.txt) DO xcopy src\%~nxF* .\dest /S /Y
What this command does is read a text file ("d:\test\list.txt" in this case), read every line, and for each file, run xcopy, adding a wildcard at the end of the file name to make sure it creates the folder structure.
I'm assuming here that:
FOR
command.You can also use the following form:
FOR /F "tokens=* delims=," %F in ('cmd') DO xcopy src\%~nxF* .\dest /S /Y
where cmd needs to be replace with the command you use to generate your list of files to copy.
Note that if you use this FOR
command in a batch file, you need to replace %F
with %%F
(and %~nxF*
with %%~nxF*
).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With