Commmand line command to copy entire directory (including directory folder) to another directory












60















using the command line, I'd like to copy one directory to another. For example there is directory C:/test and C:/test2.



I'd like to copy C:/test into C:/test2 so that the result will be C:/test2/test



Everything I've found so far will only copy the files and folders contained in C:/test into C:/test2, but leaves out the parent directory.










share|improve this question















migrated from stackoverflow.com Nov 2 '10 at 3:00


This question came from our site for professional and enthusiast programmers.














  • 1





    try to use xcopy

    – Sandeep Singh Rawat
    Nov 1 '10 at 21:53
















60















using the command line, I'd like to copy one directory to another. For example there is directory C:/test and C:/test2.



I'd like to copy C:/test into C:/test2 so that the result will be C:/test2/test



Everything I've found so far will only copy the files and folders contained in C:/test into C:/test2, but leaves out the parent directory.










share|improve this question















migrated from stackoverflow.com Nov 2 '10 at 3:00


This question came from our site for professional and enthusiast programmers.














  • 1





    try to use xcopy

    – Sandeep Singh Rawat
    Nov 1 '10 at 21:53














60












60








60


15






using the command line, I'd like to copy one directory to another. For example there is directory C:/test and C:/test2.



I'd like to copy C:/test into C:/test2 so that the result will be C:/test2/test



Everything I've found so far will only copy the files and folders contained in C:/test into C:/test2, but leaves out the parent directory.










share|improve this question
















using the command line, I'd like to copy one directory to another. For example there is directory C:/test and C:/test2.



I'd like to copy C:/test into C:/test2 so that the result will be C:/test2/test



Everything I've found so far will only copy the files and folders contained in C:/test into C:/test2, but leaves out the parent directory.







windows command-line






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Sep 3 '15 at 17:49









Scott Chamberlain

28k583101




28k583101










asked Nov 1 '10 at 21:50







agezna











migrated from stackoverflow.com Nov 2 '10 at 3:00


This question came from our site for professional and enthusiast programmers.









migrated from stackoverflow.com Nov 2 '10 at 3:00


This question came from our site for professional and enthusiast programmers.










  • 1





    try to use xcopy

    – Sandeep Singh Rawat
    Nov 1 '10 at 21:53














  • 1





    try to use xcopy

    – Sandeep Singh Rawat
    Nov 1 '10 at 21:53








1




1





try to use xcopy

– Sandeep Singh Rawat
Nov 1 '10 at 21:53





try to use xcopy

– Sandeep Singh Rawat
Nov 1 '10 at 21:53










11 Answers
11






active

oldest

votes


















47














Try using XCOPY with the /E switch. More info here.



I haven't had to access this information from my brain in years!



UPDATE



The documentation says that it copies all files and subdirectories from the source directory (meaning that the parent directory is not created), so you would have to create test in C:test2 first and then use XCOPY.






share|improve this answer





















  • 2





    The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

    – mfg
    Nov 9 '10 at 16:33






  • 2





    Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

    – user1016274
    Nov 22 '15 at 21:50






  • 2





    This actually does not provide answer for the question because folder test still nees to be created.

    – IGRACH
    Aug 18 '16 at 5:49






  • 2





    @IGRACH I thought md test and then using xcopy was trivially obvious.

    – vivin
    Aug 18 '16 at 15:53






  • 1





    Well question is about copy folder not creating new folder and then copying contens in it.

    – IGRACH
    Aug 18 '16 at 15:57





















31














xcopy c:test c:test2test /s /e /h


Here is info on XCOPY [1,2]






share|improve this answer





















  • 2





    How to stop asking me to input "D"?

    – YumYumYum
    Sep 14 '16 at 14:00






  • 2





    @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

    – Thijs Tijsma
    Jan 2 '17 at 13:40



















15














Use ROBOCOPY if you're creating backup scripts. xcopy has been deprecated and will likely be phased out of use in the near future. robocopy can do everything xcopy can. It is also more flexible and reliable. Creating scripts with robocopy will future-proof them.







  1. Use robocopy to easily copy folders. The robocopy command replaces the xcopy command. It can quickly copy entire folders without having to worry about defining the contents. For example, to copy all of the contents of the C:tools directory to the new folder D:backuptools, enter the following:



    robocopy C:tools D:backuptools /e


    The /e modifier tells robocopy to include all subdirectories. This includes empty folders.
    robocopy will automatically copy hidden and system files. It will create new directories if they don't exist at the target location.




  2. Mirror a directory. Mirroring a directory is great for making backups. The mirror option of robocopy will copy all of the contents from the source to the destination. It will then delete anything at the destination that doesn't exist at the source. This ensures that your backup only has the latest versions of your files. For example, to mirror C:UsersMy Documents to D:backupMy Documents, enter the following:[4]



    robocopy "C:UsersMy Documents" "D:backupMy Documents" /mir


    This function will preserve all permissions of the original files.




  3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy.



    robocopy "C:UsersMy Documents" "D:backupMy Documents" /z



  4. Log the copying process. robocopy allows you to create a log file. This can help you pinpoint problems or generate an archive of what's been copied.



    robocopy "C:UsersMy Documents" "D:backupMy Documents" /log+:<filename>.txt


    The /log+ modifier will append the existing log file instead of overwriting it. If you'd prefer to just overwrite the old log file, use /log:.txt.








share|improve this answer

































    8














    I recommend robocopy over xcopy, as it has a lot more options, including keeping timestamps intact, which I find essential.



    Robocopy needs to be added on XP/2003, but it is standard from Vista onwards.



    I actually usually use xxcopy, but the 64-bit version is not free.






    share|improve this answer



















    • 1





      robocopy is a Windows program. The question was about DOS.

      – grawity
      Nov 2 '10 at 20:52






    • 8





      @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

      – paradroid
      Nov 3 '10 at 8:31











    • the real question is: is robocopy a Microsoft program?

      – knocte
      Feb 26 '18 at 8:17











    • @knocte yes it is

      – yossico
      Mar 28 '18 at 15:13



















    5














    XCOPY SourceDrive: DestinationDrive: /S /E


    For example, if you need to copy E: drive data to H: drive (external hard drive) through command line or from xboot command environment.



    xboot:>XCOPY E: "H:BackupFolder" /S /E





    share|improve this answer





















    • 2





      /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

      – Giri
      Jan 15 '15 at 19:03



















    2














    If the original question is what I have been looking for an answer to then I, and obviously no one above, has come up with a clear solution.



    What I am looking for is to copy the test directory into the test2 directory without having to type it in again. Something like



    xcopy /isvy c:test d:test2


    where d:test2test does not exist before the copy but does after. This would save on miss-typing test the second time in the destination path. The above command will copy all the files and any directories into test2 but will not create the test directory.



    So far



    xcopy /isvy c:test d:test2test


    is really the only way I have found to get this job done. Again if you have typing issues there is no guarantee that the source and destination directories will match.



    An alternative to correct this is



    set mydir=test&&xcopy /isvy c:%mydir% c:test2%mydir%


    This sets the destination directory in the mydir variable then uses that variable in both the source and destination path. If you type the variable wrong you will either get an error or the destination directory will probably have % at the beginning and end.



    It is longer to type but less chance of getting the wrong names. They will be noticeable.






    share|improve this answer


























    • It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

      – NetwOrchestration
      Aug 18 '16 at 22:00





















    0














    xcopy SWITCHES SOURCE DESTINATION


    Where SWITCHES can be:





    • To copy the whole directory structure:



      /hiev




    • To overwrite files in destination (in case destination folder already exists):



      /hievry




    • To overwrite and also copy with ACL+Attribute:



      /hievxok




    Most suited to your case:



    xcopy /hievry C:test C:test2test






    share|improve this answer































      0














      I had a similar situation where I needed to copy a number of folders including the folder names to a destination location, and hoped this question marked answered would help, but it truly does not.



      Firstly, there are definitely occasions where one would need this ability and I ran into one when I had to copy folders from C:WindowsAssemblyGAC_MSIL. Windows Explorer refuses to show this folder, so you have to use a command prompt.



      If you are familiar with the GAC folder, you would know that the folder names are non-trivial and easy to get wrong if you mistype.



      So creating the directory beforehand is not really an option - unless you use a script - which I ended up using, as this was the only real solution.



      First dump the folders you want to copy to a temporary file, this is usually based on some pattern e.g.



      dir /B policy* > Folders.txt


      Then loop over the entries in the dump and copy to destination. Xcopy will take care of creating a folder if you end the destination argument with a backslash ()



      for /F "tokens=*" %%A in (Folders.txt) do xcopy /E /S %%A C:Dest%%A


      Put both these commands in a batch file and run.



      Now if only xcopy or robocopy has this built in.






      share|improve this answer































        0














        XCOPY SourceDrive: DestinationDrive: /S /E






        share|improve this answer
























        • Welcome to Super User! Can you explain this? (especially the /S /E flags)

          – bertieb
          May 15 '18 at 7:38



















        0














        I have come to a functional alternative answer for your question.



        Firstly, using FORFILES with /S parameter, confers that every sub-directory in C:test will be reached.



        Secondly, with /C parameter, it is possible to start a chain of commands with native variables, which makes possible to create the identic directories at the destination, and THEN copy the files to inside them, using two conditional structures.



        The first conditional structure @isdir==TRUE (make sure to use capital letters), allows to get directories only from source, then creating them at the destiny with MKDIR [path]@relpath at the end.



        Finally, the second one makes sure that it are working with files only with @isdir==FALSE, and then the COPY command simply gets the job done, getting all files reached by FORFILES command, setting [path]@relpath as destination, to copy the files to inside the just created directories.



        forfiles /s /c " cmd /c ( if @isdir==TRUE mkdir C:test@relpath ) && ( if @isdir==FALSE copy @file C:test2@relpath)"


        Hope that helps everyone around here.






        share|improve this answer































          -2














          This will do that from the GUI, don't know how they do it.



          "...small program will allow you to select the "from directory" and "into directory", and it will proceed to copy ONLY the directory structure."



          http://www.rjlsoftware.com/software/utility/treecopy/






          share|improve this answer























            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function() {
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled) {
            StackExchange.using("snippets", function() {
            createEditor();
            });
            }
            else {
            createEditor();
            }
            });

            function createEditor() {
            StackExchange.prepareEditor({
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            bindNavPrevention: true,
            postfix: "",
            imageUploader: {
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f206036%2fcommmand-line-command-to-copy-entire-directory-including-directory-folder-to-a%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown
























            11 Answers
            11






            active

            oldest

            votes








            11 Answers
            11






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            47














            Try using XCOPY with the /E switch. More info here.



            I haven't had to access this information from my brain in years!



            UPDATE



            The documentation says that it copies all files and subdirectories from the source directory (meaning that the parent directory is not created), so you would have to create test in C:test2 first and then use XCOPY.






            share|improve this answer





















            • 2





              The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

              – mfg
              Nov 9 '10 at 16:33






            • 2





              Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

              – user1016274
              Nov 22 '15 at 21:50






            • 2





              This actually does not provide answer for the question because folder test still nees to be created.

              – IGRACH
              Aug 18 '16 at 5:49






            • 2





              @IGRACH I thought md test and then using xcopy was trivially obvious.

              – vivin
              Aug 18 '16 at 15:53






            • 1





              Well question is about copy folder not creating new folder and then copying contens in it.

              – IGRACH
              Aug 18 '16 at 15:57


















            47














            Try using XCOPY with the /E switch. More info here.



            I haven't had to access this information from my brain in years!



            UPDATE



            The documentation says that it copies all files and subdirectories from the source directory (meaning that the parent directory is not created), so you would have to create test in C:test2 first and then use XCOPY.






            share|improve this answer





















            • 2





              The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

              – mfg
              Nov 9 '10 at 16:33






            • 2





              Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

              – user1016274
              Nov 22 '15 at 21:50






            • 2





              This actually does not provide answer for the question because folder test still nees to be created.

              – IGRACH
              Aug 18 '16 at 5:49






            • 2





              @IGRACH I thought md test and then using xcopy was trivially obvious.

              – vivin
              Aug 18 '16 at 15:53






            • 1





              Well question is about copy folder not creating new folder and then copying contens in it.

              – IGRACH
              Aug 18 '16 at 15:57
















            47












            47








            47







            Try using XCOPY with the /E switch. More info here.



            I haven't had to access this information from my brain in years!



            UPDATE



            The documentation says that it copies all files and subdirectories from the source directory (meaning that the parent directory is not created), so you would have to create test in C:test2 first and then use XCOPY.






            share|improve this answer















            Try using XCOPY with the /E switch. More info here.



            I haven't had to access this information from my brain in years!



            UPDATE



            The documentation says that it copies all files and subdirectories from the source directory (meaning that the parent directory is not created), so you would have to create test in C:test2 first and then use XCOPY.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Aug 18 '16 at 16:42

























            answered Nov 1 '10 at 21:52









            vivinvivin

            7561615




            7561615








            • 2





              The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

              – mfg
              Nov 9 '10 at 16:33






            • 2





              Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

              – user1016274
              Nov 22 '15 at 21:50






            • 2





              This actually does not provide answer for the question because folder test still nees to be created.

              – IGRACH
              Aug 18 '16 at 5:49






            • 2





              @IGRACH I thought md test and then using xcopy was trivially obvious.

              – vivin
              Aug 18 '16 at 15:53






            • 1





              Well question is about copy folder not creating new folder and then copying contens in it.

              – IGRACH
              Aug 18 '16 at 15:57
















            • 2





              The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

              – mfg
              Nov 9 '10 at 16:33






            • 2





              Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

              – user1016274
              Nov 22 '15 at 21:50






            • 2





              This actually does not provide answer for the question because folder test still nees to be created.

              – IGRACH
              Aug 18 '16 at 5:49






            • 2





              @IGRACH I thought md test and then using xcopy was trivially obvious.

              – vivin
              Aug 18 '16 at 15:53






            • 1





              Well question is about copy folder not creating new folder and then copying contens in it.

              – IGRACH
              Aug 18 '16 at 15:57










            2




            2





            The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

            – mfg
            Nov 9 '10 at 16:33





            The '/T' switch on Xcopy will do a directory & subdirectory structure copy without any files.

            – mfg
            Nov 9 '10 at 16:33




            2




            2





            Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

            – user1016274
            Nov 22 '15 at 21:50





            Better use robocopy /CREATE /COPYALL /DCOPY:T src dst to just copy the folder and empty files but preserve all timestamps and other attributes.

            – user1016274
            Nov 22 '15 at 21:50




            2




            2





            This actually does not provide answer for the question because folder test still nees to be created.

            – IGRACH
            Aug 18 '16 at 5:49





            This actually does not provide answer for the question because folder test still nees to be created.

            – IGRACH
            Aug 18 '16 at 5:49




            2




            2





            @IGRACH I thought md test and then using xcopy was trivially obvious.

            – vivin
            Aug 18 '16 at 15:53





            @IGRACH I thought md test and then using xcopy was trivially obvious.

            – vivin
            Aug 18 '16 at 15:53




            1




            1





            Well question is about copy folder not creating new folder and then copying contens in it.

            – IGRACH
            Aug 18 '16 at 15:57







            Well question is about copy folder not creating new folder and then copying contens in it.

            – IGRACH
            Aug 18 '16 at 15:57















            31














            xcopy c:test c:test2test /s /e /h


            Here is info on XCOPY [1,2]






            share|improve this answer





















            • 2





              How to stop asking me to input "D"?

              – YumYumYum
              Sep 14 '16 at 14:00






            • 2





              @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

              – Thijs Tijsma
              Jan 2 '17 at 13:40
















            31














            xcopy c:test c:test2test /s /e /h


            Here is info on XCOPY [1,2]






            share|improve this answer





















            • 2





              How to stop asking me to input "D"?

              – YumYumYum
              Sep 14 '16 at 14:00






            • 2





              @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

              – Thijs Tijsma
              Jan 2 '17 at 13:40














            31












            31








            31







            xcopy c:test c:test2test /s /e /h


            Here is info on XCOPY [1,2]






            share|improve this answer















            xcopy c:test c:test2test /s /e /h


            Here is info on XCOPY [1,2]







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 17 '15 at 17:22









            Hastur

            13.2k53268




            13.2k53268










            answered Nov 1 '10 at 21:52







            Zachary















            • 2





              How to stop asking me to input "D"?

              – YumYumYum
              Sep 14 '16 at 14:00






            • 2





              @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

              – Thijs Tijsma
              Jan 2 '17 at 13:40














            • 2





              How to stop asking me to input "D"?

              – YumYumYum
              Sep 14 '16 at 14:00






            • 2





              @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

              – Thijs Tijsma
              Jan 2 '17 at 13:40








            2




            2





            How to stop asking me to input "D"?

            – YumYumYum
            Sep 14 '16 at 14:00





            How to stop asking me to input "D"?

            – YumYumYum
            Sep 14 '16 at 14:00




            2




            2





            @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

            – Thijs Tijsma
            Jan 2 '17 at 13:40





            @YumYumYum: You can use the /I switch: " /I If destination does not exist and copying more than one file, assumes that destination must be a directory."

            – Thijs Tijsma
            Jan 2 '17 at 13:40











            15














            Use ROBOCOPY if you're creating backup scripts. xcopy has been deprecated and will likely be phased out of use in the near future. robocopy can do everything xcopy can. It is also more flexible and reliable. Creating scripts with robocopy will future-proof them.







            1. Use robocopy to easily copy folders. The robocopy command replaces the xcopy command. It can quickly copy entire folders without having to worry about defining the contents. For example, to copy all of the contents of the C:tools directory to the new folder D:backuptools, enter the following:



              robocopy C:tools D:backuptools /e


              The /e modifier tells robocopy to include all subdirectories. This includes empty folders.
              robocopy will automatically copy hidden and system files. It will create new directories if they don't exist at the target location.




            2. Mirror a directory. Mirroring a directory is great for making backups. The mirror option of robocopy will copy all of the contents from the source to the destination. It will then delete anything at the destination that doesn't exist at the source. This ensures that your backup only has the latest versions of your files. For example, to mirror C:UsersMy Documents to D:backupMy Documents, enter the following:[4]



              robocopy "C:UsersMy Documents" "D:backupMy Documents" /mir


              This function will preserve all permissions of the original files.




            3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy.



              robocopy "C:UsersMy Documents" "D:backupMy Documents" /z



            4. Log the copying process. robocopy allows you to create a log file. This can help you pinpoint problems or generate an archive of what's been copied.



              robocopy "C:UsersMy Documents" "D:backupMy Documents" /log+:<filename>.txt


              The /log+ modifier will append the existing log file instead of overwriting it. If you'd prefer to just overwrite the old log file, use /log:.txt.








            share|improve this answer






























              15














              Use ROBOCOPY if you're creating backup scripts. xcopy has been deprecated and will likely be phased out of use in the near future. robocopy can do everything xcopy can. It is also more flexible and reliable. Creating scripts with robocopy will future-proof them.







              1. Use robocopy to easily copy folders. The robocopy command replaces the xcopy command. It can quickly copy entire folders without having to worry about defining the contents. For example, to copy all of the contents of the C:tools directory to the new folder D:backuptools, enter the following:



                robocopy C:tools D:backuptools /e


                The /e modifier tells robocopy to include all subdirectories. This includes empty folders.
                robocopy will automatically copy hidden and system files. It will create new directories if they don't exist at the target location.




              2. Mirror a directory. Mirroring a directory is great for making backups. The mirror option of robocopy will copy all of the contents from the source to the destination. It will then delete anything at the destination that doesn't exist at the source. This ensures that your backup only has the latest versions of your files. For example, to mirror C:UsersMy Documents to D:backupMy Documents, enter the following:[4]



                robocopy "C:UsersMy Documents" "D:backupMy Documents" /mir


                This function will preserve all permissions of the original files.




              3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy.



                robocopy "C:UsersMy Documents" "D:backupMy Documents" /z



              4. Log the copying process. robocopy allows you to create a log file. This can help you pinpoint problems or generate an archive of what's been copied.



                robocopy "C:UsersMy Documents" "D:backupMy Documents" /log+:<filename>.txt


                The /log+ modifier will append the existing log file instead of overwriting it. If you'd prefer to just overwrite the old log file, use /log:.txt.








              share|improve this answer




























                15












                15








                15







                Use ROBOCOPY if you're creating backup scripts. xcopy has been deprecated and will likely be phased out of use in the near future. robocopy can do everything xcopy can. It is also more flexible and reliable. Creating scripts with robocopy will future-proof them.







                1. Use robocopy to easily copy folders. The robocopy command replaces the xcopy command. It can quickly copy entire folders without having to worry about defining the contents. For example, to copy all of the contents of the C:tools directory to the new folder D:backuptools, enter the following:



                  robocopy C:tools D:backuptools /e


                  The /e modifier tells robocopy to include all subdirectories. This includes empty folders.
                  robocopy will automatically copy hidden and system files. It will create new directories if they don't exist at the target location.




                2. Mirror a directory. Mirroring a directory is great for making backups. The mirror option of robocopy will copy all of the contents from the source to the destination. It will then delete anything at the destination that doesn't exist at the source. This ensures that your backup only has the latest versions of your files. For example, to mirror C:UsersMy Documents to D:backupMy Documents, enter the following:[4]



                  robocopy "C:UsersMy Documents" "D:backupMy Documents" /mir


                  This function will preserve all permissions of the original files.




                3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy.



                  robocopy "C:UsersMy Documents" "D:backupMy Documents" /z



                4. Log the copying process. robocopy allows you to create a log file. This can help you pinpoint problems or generate an archive of what's been copied.



                  robocopy "C:UsersMy Documents" "D:backupMy Documents" /log+:<filename>.txt


                  The /log+ modifier will append the existing log file instead of overwriting it. If you'd prefer to just overwrite the old log file, use /log:.txt.








                share|improve this answer















                Use ROBOCOPY if you're creating backup scripts. xcopy has been deprecated and will likely be phased out of use in the near future. robocopy can do everything xcopy can. It is also more flexible and reliable. Creating scripts with robocopy will future-proof them.







                1. Use robocopy to easily copy folders. The robocopy command replaces the xcopy command. It can quickly copy entire folders without having to worry about defining the contents. For example, to copy all of the contents of the C:tools directory to the new folder D:backuptools, enter the following:



                  robocopy C:tools D:backuptools /e


                  The /e modifier tells robocopy to include all subdirectories. This includes empty folders.
                  robocopy will automatically copy hidden and system files. It will create new directories if they don't exist at the target location.




                2. Mirror a directory. Mirroring a directory is great for making backups. The mirror option of robocopy will copy all of the contents from the source to the destination. It will then delete anything at the destination that doesn't exist at the source. This ensures that your backup only has the latest versions of your files. For example, to mirror C:UsersMy Documents to D:backupMy Documents, enter the following:[4]



                  robocopy "C:UsersMy Documents" "D:backupMy Documents" /mir


                  This function will preserve all permissions of the original files.




                3. Enable restarting. You may want to include the ability to restart the process in case the connection is severed mid-copy.



                  robocopy "C:UsersMy Documents" "D:backupMy Documents" /z



                4. Log the copying process. robocopy allows you to create a log file. This can help you pinpoint problems or generate an archive of what's been copied.



                  robocopy "C:UsersMy Documents" "D:backupMy Documents" /log+:<filename>.txt


                  The /log+ modifier will append the existing log file instead of overwriting it. If you'd prefer to just overwrite the old log file, use /log:.txt.









                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 22 '15 at 21:38

























                answered Nov 22 '15 at 21:23









                Program-Me-RevProgram-Me-Rev

                2651310




                2651310























                    8














                    I recommend robocopy over xcopy, as it has a lot more options, including keeping timestamps intact, which I find essential.



                    Robocopy needs to be added on XP/2003, but it is standard from Vista onwards.



                    I actually usually use xxcopy, but the 64-bit version is not free.






                    share|improve this answer



















                    • 1





                      robocopy is a Windows program. The question was about DOS.

                      – grawity
                      Nov 2 '10 at 20:52






                    • 8





                      @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

                      – paradroid
                      Nov 3 '10 at 8:31











                    • the real question is: is robocopy a Microsoft program?

                      – knocte
                      Feb 26 '18 at 8:17











                    • @knocte yes it is

                      – yossico
                      Mar 28 '18 at 15:13
















                    8














                    I recommend robocopy over xcopy, as it has a lot more options, including keeping timestamps intact, which I find essential.



                    Robocopy needs to be added on XP/2003, but it is standard from Vista onwards.



                    I actually usually use xxcopy, but the 64-bit version is not free.






                    share|improve this answer



















                    • 1





                      robocopy is a Windows program. The question was about DOS.

                      – grawity
                      Nov 2 '10 at 20:52






                    • 8





                      @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

                      – paradroid
                      Nov 3 '10 at 8:31











                    • the real question is: is robocopy a Microsoft program?

                      – knocte
                      Feb 26 '18 at 8:17











                    • @knocte yes it is

                      – yossico
                      Mar 28 '18 at 15:13














                    8












                    8








                    8







                    I recommend robocopy over xcopy, as it has a lot more options, including keeping timestamps intact, which I find essential.



                    Robocopy needs to be added on XP/2003, but it is standard from Vista onwards.



                    I actually usually use xxcopy, but the 64-bit version is not free.






                    share|improve this answer













                    I recommend robocopy over xcopy, as it has a lot more options, including keeping timestamps intact, which I find essential.



                    Robocopy needs to be added on XP/2003, but it is standard from Vista onwards.



                    I actually usually use xxcopy, but the 64-bit version is not free.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Nov 2 '10 at 3:09









                    paradroidparadroid

                    19.3k958102




                    19.3k958102








                    • 1





                      robocopy is a Windows program. The question was about DOS.

                      – grawity
                      Nov 2 '10 at 20:52






                    • 8





                      @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

                      – paradroid
                      Nov 3 '10 at 8:31











                    • the real question is: is robocopy a Microsoft program?

                      – knocte
                      Feb 26 '18 at 8:17











                    • @knocte yes it is

                      – yossico
                      Mar 28 '18 at 15:13














                    • 1





                      robocopy is a Windows program. The question was about DOS.

                      – grawity
                      Nov 2 '10 at 20:52






                    • 8





                      @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

                      – paradroid
                      Nov 3 '10 at 8:31











                    • the real question is: is robocopy a Microsoft program?

                      – knocte
                      Feb 26 '18 at 8:17











                    • @knocte yes it is

                      – yossico
                      Mar 28 '18 at 15:13








                    1




                    1





                    robocopy is a Windows program. The question was about DOS.

                    – grawity
                    Nov 2 '10 at 20:52





                    robocopy is a Windows program. The question was about DOS.

                    – grawity
                    Nov 2 '10 at 20:52




                    8




                    8





                    @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

                    – paradroid
                    Nov 3 '10 at 8:31





                    @grawity: The likelihood of him actually using 16-bit DOS is very small compared to the high probability of him calling CMD 'DOS', as is common in the real world.

                    – paradroid
                    Nov 3 '10 at 8:31













                    the real question is: is robocopy a Microsoft program?

                    – knocte
                    Feb 26 '18 at 8:17





                    the real question is: is robocopy a Microsoft program?

                    – knocte
                    Feb 26 '18 at 8:17













                    @knocte yes it is

                    – yossico
                    Mar 28 '18 at 15:13





                    @knocte yes it is

                    – yossico
                    Mar 28 '18 at 15:13











                    5














                    XCOPY SourceDrive: DestinationDrive: /S /E


                    For example, if you need to copy E: drive data to H: drive (external hard drive) through command line or from xboot command environment.



                    xboot:>XCOPY E: "H:BackupFolder" /S /E





                    share|improve this answer





















                    • 2





                      /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

                      – Giri
                      Jan 15 '15 at 19:03
















                    5














                    XCOPY SourceDrive: DestinationDrive: /S /E


                    For example, if you need to copy E: drive data to H: drive (external hard drive) through command line or from xboot command environment.



                    xboot:>XCOPY E: "H:BackupFolder" /S /E





                    share|improve this answer





















                    • 2





                      /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

                      – Giri
                      Jan 15 '15 at 19:03














                    5












                    5








                    5







                    XCOPY SourceDrive: DestinationDrive: /S /E


                    For example, if you need to copy E: drive data to H: drive (external hard drive) through command line or from xboot command environment.



                    xboot:>XCOPY E: "H:BackupFolder" /S /E





                    share|improve this answer















                    XCOPY SourceDrive: DestinationDrive: /S /E


                    For example, if you need to copy E: drive data to H: drive (external hard drive) through command line or from xboot command environment.



                    xboot:>XCOPY E: "H:BackupFolder" /S /E






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Oct 19 '12 at 22:07









                    Malachi

                    9231926




                    9231926










                    answered Jun 22 '12 at 6:40









                    Syed khalid MohammedSyed khalid Mohammed

                    5911




                    5911








                    • 2





                      /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

                      – Giri
                      Jan 15 '15 at 19:03














                    • 2





                      /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

                      – Giri
                      Jan 15 '15 at 19:03








                    2




                    2





                    /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

                    – Giri
                    Jan 15 '15 at 19:03





                    /S is not required when /E is present. windows-commandline.com/copy-directory-command-line

                    – Giri
                    Jan 15 '15 at 19:03











                    2














                    If the original question is what I have been looking for an answer to then I, and obviously no one above, has come up with a clear solution.



                    What I am looking for is to copy the test directory into the test2 directory without having to type it in again. Something like



                    xcopy /isvy c:test d:test2


                    where d:test2test does not exist before the copy but does after. This would save on miss-typing test the second time in the destination path. The above command will copy all the files and any directories into test2 but will not create the test directory.



                    So far



                    xcopy /isvy c:test d:test2test


                    is really the only way I have found to get this job done. Again if you have typing issues there is no guarantee that the source and destination directories will match.



                    An alternative to correct this is



                    set mydir=test&&xcopy /isvy c:%mydir% c:test2%mydir%


                    This sets the destination directory in the mydir variable then uses that variable in both the source and destination path. If you type the variable wrong you will either get an error or the destination directory will probably have % at the beginning and end.



                    It is longer to type but less chance of getting the wrong names. They will be noticeable.






                    share|improve this answer


























                    • It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

                      – NetwOrchestration
                      Aug 18 '16 at 22:00


















                    2














                    If the original question is what I have been looking for an answer to then I, and obviously no one above, has come up with a clear solution.



                    What I am looking for is to copy the test directory into the test2 directory without having to type it in again. Something like



                    xcopy /isvy c:test d:test2


                    where d:test2test does not exist before the copy but does after. This would save on miss-typing test the second time in the destination path. The above command will copy all the files and any directories into test2 but will not create the test directory.



                    So far



                    xcopy /isvy c:test d:test2test


                    is really the only way I have found to get this job done. Again if you have typing issues there is no guarantee that the source and destination directories will match.



                    An alternative to correct this is



                    set mydir=test&&xcopy /isvy c:%mydir% c:test2%mydir%


                    This sets the destination directory in the mydir variable then uses that variable in both the source and destination path. If you type the variable wrong you will either get an error or the destination directory will probably have % at the beginning and end.



                    It is longer to type but less chance of getting the wrong names. They will be noticeable.






                    share|improve this answer


























                    • It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

                      – NetwOrchestration
                      Aug 18 '16 at 22:00
















                    2












                    2








                    2







                    If the original question is what I have been looking for an answer to then I, and obviously no one above, has come up with a clear solution.



                    What I am looking for is to copy the test directory into the test2 directory without having to type it in again. Something like



                    xcopy /isvy c:test d:test2


                    where d:test2test does not exist before the copy but does after. This would save on miss-typing test the second time in the destination path. The above command will copy all the files and any directories into test2 but will not create the test directory.



                    So far



                    xcopy /isvy c:test d:test2test


                    is really the only way I have found to get this job done. Again if you have typing issues there is no guarantee that the source and destination directories will match.



                    An alternative to correct this is



                    set mydir=test&&xcopy /isvy c:%mydir% c:test2%mydir%


                    This sets the destination directory in the mydir variable then uses that variable in both the source and destination path. If you type the variable wrong you will either get an error or the destination directory will probably have % at the beginning and end.



                    It is longer to type but less chance of getting the wrong names. They will be noticeable.






                    share|improve this answer















                    If the original question is what I have been looking for an answer to then I, and obviously no one above, has come up with a clear solution.



                    What I am looking for is to copy the test directory into the test2 directory without having to type it in again. Something like



                    xcopy /isvy c:test d:test2


                    where d:test2test does not exist before the copy but does after. This would save on miss-typing test the second time in the destination path. The above command will copy all the files and any directories into test2 but will not create the test directory.



                    So far



                    xcopy /isvy c:test d:test2test


                    is really the only way I have found to get this job done. Again if you have typing issues there is no guarantee that the source and destination directories will match.



                    An alternative to correct this is



                    set mydir=test&&xcopy /isvy c:%mydir% c:test2%mydir%


                    This sets the destination directory in the mydir variable then uses that variable in both the source and destination path. If you type the variable wrong you will either get an error or the destination directory will probably have % at the beginning and end.



                    It is longer to type but less chance of getting the wrong names. They will be noticeable.







                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited May 6 '16 at 10:09









                    Burgi

                    3,929102644




                    3,929102644










                    answered Apr 29 '16 at 18:29









                    BillBill

                    311




                    311













                    • It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

                      – NetwOrchestration
                      Aug 18 '16 at 22:00





















                    • It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

                      – NetwOrchestration
                      Aug 18 '16 at 22:00



















                    It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

                    – NetwOrchestration
                    Aug 18 '16 at 22:00







                    It's actually xcopy /ievy c:test d:test2test to keep directory tree structure, and in set mydir=test&xcopy /isvy c:%mydir% c:test2%mydir% only 1 & will suffice, since the result of setting a value is always successful.

                    – NetwOrchestration
                    Aug 18 '16 at 22:00













                    0














                    xcopy SWITCHES SOURCE DESTINATION


                    Where SWITCHES can be:





                    • To copy the whole directory structure:



                      /hiev




                    • To overwrite files in destination (in case destination folder already exists):



                      /hievry




                    • To overwrite and also copy with ACL+Attribute:



                      /hievxok




                    Most suited to your case:



                    xcopy /hievry C:test C:test2test






                    share|improve this answer




























                      0














                      xcopy SWITCHES SOURCE DESTINATION


                      Where SWITCHES can be:





                      • To copy the whole directory structure:



                        /hiev




                      • To overwrite files in destination (in case destination folder already exists):



                        /hievry




                      • To overwrite and also copy with ACL+Attribute:



                        /hievxok




                      Most suited to your case:



                      xcopy /hievry C:test C:test2test






                      share|improve this answer


























                        0












                        0








                        0







                        xcopy SWITCHES SOURCE DESTINATION


                        Where SWITCHES can be:





                        • To copy the whole directory structure:



                          /hiev




                        • To overwrite files in destination (in case destination folder already exists):



                          /hievry




                        • To overwrite and also copy with ACL+Attribute:



                          /hievxok




                        Most suited to your case:



                        xcopy /hievry C:test C:test2test






                        share|improve this answer













                        xcopy SWITCHES SOURCE DESTINATION


                        Where SWITCHES can be:





                        • To copy the whole directory structure:



                          /hiev




                        • To overwrite files in destination (in case destination folder already exists):



                          /hievry




                        • To overwrite and also copy with ACL+Attribute:



                          /hievxok




                        Most suited to your case:



                        xcopy /hievry C:test C:test2test







                        share|improve this answer












                        share|improve this answer



                        share|improve this answer










                        answered Aug 18 '16 at 22:26









                        NetwOrchestrationNetwOrchestration

                        2,00211127




                        2,00211127























                            0














                            I had a similar situation where I needed to copy a number of folders including the folder names to a destination location, and hoped this question marked answered would help, but it truly does not.



                            Firstly, there are definitely occasions where one would need this ability and I ran into one when I had to copy folders from C:WindowsAssemblyGAC_MSIL. Windows Explorer refuses to show this folder, so you have to use a command prompt.



                            If you are familiar with the GAC folder, you would know that the folder names are non-trivial and easy to get wrong if you mistype.



                            So creating the directory beforehand is not really an option - unless you use a script - which I ended up using, as this was the only real solution.



                            First dump the folders you want to copy to a temporary file, this is usually based on some pattern e.g.



                            dir /B policy* > Folders.txt


                            Then loop over the entries in the dump and copy to destination. Xcopy will take care of creating a folder if you end the destination argument with a backslash ()



                            for /F "tokens=*" %%A in (Folders.txt) do xcopy /E /S %%A C:Dest%%A


                            Put both these commands in a batch file and run.



                            Now if only xcopy or robocopy has this built in.






                            share|improve this answer




























                              0














                              I had a similar situation where I needed to copy a number of folders including the folder names to a destination location, and hoped this question marked answered would help, but it truly does not.



                              Firstly, there are definitely occasions where one would need this ability and I ran into one when I had to copy folders from C:WindowsAssemblyGAC_MSIL. Windows Explorer refuses to show this folder, so you have to use a command prompt.



                              If you are familiar with the GAC folder, you would know that the folder names are non-trivial and easy to get wrong if you mistype.



                              So creating the directory beforehand is not really an option - unless you use a script - which I ended up using, as this was the only real solution.



                              First dump the folders you want to copy to a temporary file, this is usually based on some pattern e.g.



                              dir /B policy* > Folders.txt


                              Then loop over the entries in the dump and copy to destination. Xcopy will take care of creating a folder if you end the destination argument with a backslash ()



                              for /F "tokens=*" %%A in (Folders.txt) do xcopy /E /S %%A C:Dest%%A


                              Put both these commands in a batch file and run.



                              Now if only xcopy or robocopy has this built in.






                              share|improve this answer


























                                0












                                0








                                0







                                I had a similar situation where I needed to copy a number of folders including the folder names to a destination location, and hoped this question marked answered would help, but it truly does not.



                                Firstly, there are definitely occasions where one would need this ability and I ran into one when I had to copy folders from C:WindowsAssemblyGAC_MSIL. Windows Explorer refuses to show this folder, so you have to use a command prompt.



                                If you are familiar with the GAC folder, you would know that the folder names are non-trivial and easy to get wrong if you mistype.



                                So creating the directory beforehand is not really an option - unless you use a script - which I ended up using, as this was the only real solution.



                                First dump the folders you want to copy to a temporary file, this is usually based on some pattern e.g.



                                dir /B policy* > Folders.txt


                                Then loop over the entries in the dump and copy to destination. Xcopy will take care of creating a folder if you end the destination argument with a backslash ()



                                for /F "tokens=*" %%A in (Folders.txt) do xcopy /E /S %%A C:Dest%%A


                                Put both these commands in a batch file and run.



                                Now if only xcopy or robocopy has this built in.






                                share|improve this answer













                                I had a similar situation where I needed to copy a number of folders including the folder names to a destination location, and hoped this question marked answered would help, but it truly does not.



                                Firstly, there are definitely occasions where one would need this ability and I ran into one when I had to copy folders from C:WindowsAssemblyGAC_MSIL. Windows Explorer refuses to show this folder, so you have to use a command prompt.



                                If you are familiar with the GAC folder, you would know that the folder names are non-trivial and easy to get wrong if you mistype.



                                So creating the directory beforehand is not really an option - unless you use a script - which I ended up using, as this was the only real solution.



                                First dump the folders you want to copy to a temporary file, this is usually based on some pattern e.g.



                                dir /B policy* > Folders.txt


                                Then loop over the entries in the dump and copy to destination. Xcopy will take care of creating a folder if you end the destination argument with a backslash ()



                                for /F "tokens=*" %%A in (Folders.txt) do xcopy /E /S %%A C:Dest%%A


                                Put both these commands in a batch file and run.



                                Now if only xcopy or robocopy has this built in.







                                share|improve this answer












                                share|improve this answer



                                share|improve this answer










                                answered Jul 24 '17 at 12:06









                                mahendrentmahendrent

                                1




                                1























                                    0














                                    XCOPY SourceDrive: DestinationDrive: /S /E






                                    share|improve this answer
























                                    • Welcome to Super User! Can you explain this? (especially the /S /E flags)

                                      – bertieb
                                      May 15 '18 at 7:38
















                                    0














                                    XCOPY SourceDrive: DestinationDrive: /S /E






                                    share|improve this answer
























                                    • Welcome to Super User! Can you explain this? (especially the /S /E flags)

                                      – bertieb
                                      May 15 '18 at 7:38














                                    0












                                    0








                                    0







                                    XCOPY SourceDrive: DestinationDrive: /S /E






                                    share|improve this answer













                                    XCOPY SourceDrive: DestinationDrive: /S /E







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered May 15 '18 at 5:24









                                    Noor All SafaetNoor All Safaet

                                    1




                                    1













                                    • Welcome to Super User! Can you explain this? (especially the /S /E flags)

                                      – bertieb
                                      May 15 '18 at 7:38



















                                    • Welcome to Super User! Can you explain this? (especially the /S /E flags)

                                      – bertieb
                                      May 15 '18 at 7:38

















                                    Welcome to Super User! Can you explain this? (especially the /S /E flags)

                                    – bertieb
                                    May 15 '18 at 7:38





                                    Welcome to Super User! Can you explain this? (especially the /S /E flags)

                                    – bertieb
                                    May 15 '18 at 7:38











                                    0














                                    I have come to a functional alternative answer for your question.



                                    Firstly, using FORFILES with /S parameter, confers that every sub-directory in C:test will be reached.



                                    Secondly, with /C parameter, it is possible to start a chain of commands with native variables, which makes possible to create the identic directories at the destination, and THEN copy the files to inside them, using two conditional structures.



                                    The first conditional structure @isdir==TRUE (make sure to use capital letters), allows to get directories only from source, then creating them at the destiny with MKDIR [path]@relpath at the end.



                                    Finally, the second one makes sure that it are working with files only with @isdir==FALSE, and then the COPY command simply gets the job done, getting all files reached by FORFILES command, setting [path]@relpath as destination, to copy the files to inside the just created directories.



                                    forfiles /s /c " cmd /c ( if @isdir==TRUE mkdir C:test@relpath ) && ( if @isdir==FALSE copy @file C:test2@relpath)"


                                    Hope that helps everyone around here.






                                    share|improve this answer




























                                      0














                                      I have come to a functional alternative answer for your question.



                                      Firstly, using FORFILES with /S parameter, confers that every sub-directory in C:test will be reached.



                                      Secondly, with /C parameter, it is possible to start a chain of commands with native variables, which makes possible to create the identic directories at the destination, and THEN copy the files to inside them, using two conditional structures.



                                      The first conditional structure @isdir==TRUE (make sure to use capital letters), allows to get directories only from source, then creating them at the destiny with MKDIR [path]@relpath at the end.



                                      Finally, the second one makes sure that it are working with files only with @isdir==FALSE, and then the COPY command simply gets the job done, getting all files reached by FORFILES command, setting [path]@relpath as destination, to copy the files to inside the just created directories.



                                      forfiles /s /c " cmd /c ( if @isdir==TRUE mkdir C:test@relpath ) && ( if @isdir==FALSE copy @file C:test2@relpath)"


                                      Hope that helps everyone around here.






                                      share|improve this answer


























                                        0












                                        0








                                        0







                                        I have come to a functional alternative answer for your question.



                                        Firstly, using FORFILES with /S parameter, confers that every sub-directory in C:test will be reached.



                                        Secondly, with /C parameter, it is possible to start a chain of commands with native variables, which makes possible to create the identic directories at the destination, and THEN copy the files to inside them, using two conditional structures.



                                        The first conditional structure @isdir==TRUE (make sure to use capital letters), allows to get directories only from source, then creating them at the destiny with MKDIR [path]@relpath at the end.



                                        Finally, the second one makes sure that it are working with files only with @isdir==FALSE, and then the COPY command simply gets the job done, getting all files reached by FORFILES command, setting [path]@relpath as destination, to copy the files to inside the just created directories.



                                        forfiles /s /c " cmd /c ( if @isdir==TRUE mkdir C:test@relpath ) && ( if @isdir==FALSE copy @file C:test2@relpath)"


                                        Hope that helps everyone around here.






                                        share|improve this answer













                                        I have come to a functional alternative answer for your question.



                                        Firstly, using FORFILES with /S parameter, confers that every sub-directory in C:test will be reached.



                                        Secondly, with /C parameter, it is possible to start a chain of commands with native variables, which makes possible to create the identic directories at the destination, and THEN copy the files to inside them, using two conditional structures.



                                        The first conditional structure @isdir==TRUE (make sure to use capital letters), allows to get directories only from source, then creating them at the destiny with MKDIR [path]@relpath at the end.



                                        Finally, the second one makes sure that it are working with files only with @isdir==FALSE, and then the COPY command simply gets the job done, getting all files reached by FORFILES command, setting [path]@relpath as destination, to copy the files to inside the just created directories.



                                        forfiles /s /c " cmd /c ( if @isdir==TRUE mkdir C:test@relpath ) && ( if @isdir==FALSE copy @file C:test2@relpath)"


                                        Hope that helps everyone around here.







                                        share|improve this answer












                                        share|improve this answer



                                        share|improve this answer










                                        answered Dec 7 '18 at 17:07









                                        MauGusVicenMauGusVicen

                                        1




                                        1























                                            -2














                                            This will do that from the GUI, don't know how they do it.



                                            "...small program will allow you to select the "from directory" and "into directory", and it will proceed to copy ONLY the directory structure."



                                            http://www.rjlsoftware.com/software/utility/treecopy/






                                            share|improve this answer




























                                              -2














                                              This will do that from the GUI, don't know how they do it.



                                              "...small program will allow you to select the "from directory" and "into directory", and it will proceed to copy ONLY the directory structure."



                                              http://www.rjlsoftware.com/software/utility/treecopy/






                                              share|improve this answer


























                                                -2












                                                -2








                                                -2







                                                This will do that from the GUI, don't know how they do it.



                                                "...small program will allow you to select the "from directory" and "into directory", and it will proceed to copy ONLY the directory structure."



                                                http://www.rjlsoftware.com/software/utility/treecopy/






                                                share|improve this answer













                                                This will do that from the GUI, don't know how they do it.



                                                "...small program will allow you to select the "from directory" and "into directory", and it will proceed to copy ONLY the directory structure."



                                                http://www.rjlsoftware.com/software/utility/treecopy/







                                                share|improve this answer












                                                share|improve this answer



                                                share|improve this answer










                                                answered Nov 2 '10 at 5:24









                                                NginUSNginUS

                                                42128




                                                42128






























                                                    draft saved

                                                    draft discarded




















































                                                    Thanks for contributing an answer to Super User!


                                                    • Please be sure to answer the question. Provide details and share your research!

                                                    But avoid



                                                    • Asking for help, clarification, or responding to other answers.

                                                    • Making statements based on opinion; back them up with references or personal experience.


                                                    To learn more, see our tips on writing great answers.




                                                    draft saved


                                                    draft discarded














                                                    StackExchange.ready(
                                                    function () {
                                                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f206036%2fcommmand-line-command-to-copy-entire-directory-including-directory-folder-to-a%23new-answer', 'question_page');
                                                    }
                                                    );

                                                    Post as a guest















                                                    Required, but never shown





















































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown

































                                                    Required, but never shown














                                                    Required, but never shown












                                                    Required, but never shown







                                                    Required, but never shown







                                                    Popular posts from this blog

                                                    How to reconfigure Docker Trusted Registry 2.x.x to use CEPH FS mount instead of NFS and other traditional...

                                                    is 'sed' thread safe

                                                    How to make a Squid Proxy server?