1

Need expert to help me to do simple window .bat file to copy files/folder into different specific folder

ProjectDevFolder
    /module1
        /module1-1
        /module1-2
    /module2
        /module2-1
            /module2-1-1
                /module2-1-1-1
        /module2-2
    /images
    /css
    /jquery
    /classes
    .jspfile1
    .jspfile2
    .jspfile3
    .jspfile4

To test destination

wwwFolder
    /module1
        /module1-1
        /module1-2
    /module2
        /module2-1
            /module2-1-1
                /module2-1-1-1
        /module2-2
    /images
    /css
    /jquery
    /classes
    .jspfile1
    .jspfile2
    .jspfile3
    .jspfile4

Example of window command prompt

C:\DeployScript.bat
To copy : css module2-1-1-1 jquery *(user can input multiple value with any seperator eg:space is the seperator)*
 - Status deploy css  -done
 - Status deploy module2-1-1-1  -done
 - Status deploy jquery  -done

To copy :   *(Next command)*

Thank you

Joe Ijam
  • 2,123
  • 4
  • 19
  • 30
  • Just as an aside: theoretically, some subfolders might have identical names, like e.g. `Documentation` in `Employees` and in `Customers`. Your example of user input doesn't seem to let you tell one `Documentation` folder from the other. – Andriy M Sep 24 '12 at 11:50

2 Answers2

1

This problem can be split into at least two problems:

  • Split user input
  • Copy directories
    • Find directories recursively (module2-1-1-1)

Some questions to clarify:

  • How to enter the destination root directory
  • What happens if a destination folder (or a subfolder there of) exists already?

Here are some pointers for those two problems:

Community
  • 1
  • 1
marapet
  • 54,856
  • 12
  • 170
  • 184
  • I plan to hard code the destination in the batch file eg : css ==> destination/Folder/css , images to image destination, default source is to home destination folder... If the folder does not exists, how can we create automatically recursively for any children folder – Joe Ijam Sep 25 '12 at 02:00
1

This will copy all files and subdirectories (including empty ones) from sourceDir to targetDir.

XCOPY /S /E /I sourceDir targetDir

targetDir does not need to exist. XCOPY will create it if need be.
To exclude empty directories, leave out the /e.

To exclude files, create a text file containing the names of the files to exclude, and use this command:

XCOPY /S /E /I /EXCLUDE:files.txt sourceDir targetDir

To learn more about xcopy, type XCOPY /? ENTER at the command prompt.

James K
  • 4,005
  • 4
  • 20
  • 28