A Brief Discussion on Windows File Copy

Table of contents

         I. Introduction

2. Several ways to copy files

          1. Use the copy command

          2. Use the xcopy command

          3. Use the robocopy command

          4. Use copy-item in powershell

          5. Use a third-party copy tool


I. Introduction

        In daily work, we often need to spend a lot of time and energy on file copying, so it is particularly necessary to master one or more methods of copying files.


2. Several ways to copy files

         1. Use the copy command

               1) Copy all the files under the folder t1 to the folder, which can be used on the command line

                 copy t1\* t2

                 

               2) Merge all files under folder t1 into file t2.txt, which can be used on the command line

                 copy t1\* t2.txt

                

                 Pros: Ability to combine multiple files into a single file

                 Disadvantages: Cannot copy according to the hierarchical directory of the source folder

         2. Use the xcopy command to copy

                 1) Copy the folder t1 and its subfolders to the folder t2 according to the directory level

                 

                  

                 2) Copy the folder t1 and its subfolders to the folder t2 according to the directory level but exclude t3\1.txt

                  

                   It can be seen that the /EXCLUDE switch is added to the xcopy command, and the excluded path can be added to the file pointed to by the switch to exclude the path

                   

                  3) Copy the folder t1 and its subfolders to the folder t2 according to the modification date of the file

                      The time filter switch is /D: 05-14-2023, indicating May 14, 2023

                      

                      

                  4) Copy the files or directories under folder t1 and its subfolders with the same relative path as under t2 to folder t2

                      That is to overwrite the files with the same path under t1 and t2 to t2

                      

                       In the above example, there is only 1.txt file under t2, and there is also 1.txt under t1, so only this file is overwritten

                   5) To copy large files, you can add the switch /J, similar to the mechanism of file memory mapping

                                

                              

                   6) According to the directory hierarchy, only the directory structure is copied without copying the files

                           Use xcopy t1 t2 /S /E /T

         3. Use the robocopy command

                   The robocopy function can be said to be very powerful. It can not only copy files, but also move files, and supports multi-threaded copying. The progress will be displayed when copying or moving, but there is no GUI interface.

                For example, open 4 threads to copy the t1 folder and its subfolders to the t2 folder according to the directory structure

             

         4. Use copy-item in powershell

                   1)  Copy all files under the t1 folder and its subfolders to t2 according to the directory level

                        copy-item t1\* -recurse t2

                    

         5. Use a third-party copy tool

              For example, fastcopy is suitable for copying large amounts of data

              

         

Guess you like

Origin blog.csdn.net/weixin_38526093/article/details/130673024