Search code examples
xcopypost-build-event

XCOPY switch to create specified directory if it doesn't exist?


I am using XCOPY in a post-build event to copy compiled DLLs from their output folders to the main app's output folder. The DLLs are being copied to a "Modules" subfolder in the main app output folder, like this:

xcopy  "$(TargetPath)" "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\" 

The command works fine if the Modules folder exists, but I have discovered during testing that if the folder doesn't exist, XCOPY doesn't create it, and the command fails.

Is there an XCOPY switch that will cause the folder to be created if it doesn't exist? If not, what would I add to my post-build event to create the folder if it doesn't exist? Thanks for your help.


Solution

  • I tried this on the command line using

    D:\>xcopy myfile.dat xcopytest\test\
    

    and the target directory was properly created.

    If not you can create the target dir using the mkdir command with cmd's command extensions enabled like

    cmd /x /c mkdir "$(SolutionDir)Prism4Demo.Shell\$(OutDir)Modules\"
    

    ('/x' enables command extensions in case they're not enabled by default on your system, I'm not that familiar with cmd)

    use

    cmd /? 
    mkdir /?
    xcopy /?
    

    for further information :)