Search code examples
batch-filewindows-xpcopyxcopy

xcopy does not create directory structure


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


  1. I have tried to run it in destination folder C:\destinationfolder by specifying a . for target folder
  2. Tried it without any target in above

There 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>


Solution

  • UPDATE

    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.