copying all contents of folder to another folder using batch file?

后端 未结 12 1736
时光取名叫无心
时光取名叫无心 2020-12-12 19:49

I have a folder in C:\\Folder1

I want to copy all the contents of Folder1 to another location, D:\\Folder2

How do I do

相关标签:
12条回答
  • 2020-12-12 20:23

    Here's a solution with robocopy which copies the content of Folder1 into Folder2 going trough all subdirectories and automatically overwriting the files with the same name:

    robocopy C:\Folder1 C:\Folder2 /COPYALL /E /IS /IT
    

    Here:

    /COPYALL copies all file information
    /E copies subdirectories including empty directories
    /IS includes the same files
    /IT includes modified files with the same name

    For more parameters see the official documentation: https://docs.microsoft.com/en-us/windows-server/administration/windows-commands/robocopy

    Note: it can be necessary to run the command as administrator, because of the argument /COPYALL. If you can't: just get rid of it.

    0 讨论(0)
  • 2020-12-12 20:26
    @echo off
    xcopy /s C:\yourfile C:\anotherfile\
    

    This is how it is done! Simple, right?

    0 讨论(0)
  • 2020-12-12 20:26

    I have written a .bat file to copy and paste file to a temporary folder and make it zip and transfer into a smb mount point, Hope this would help,

        @echo off
        if not exist "C:\Temp Backup\" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
        if not exist "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP"
        if not exist "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs" mkdir "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
        xcopy /s/e/q "C:\Source" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
       Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
        "C:\Program Files (x86)\WinRAR\WinRAR.exe" a  "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP\ZIP_Backup_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.rar" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\TELIUM"
        "C:\Program Files (x86)\WinRAR\WinRAR.exe" a  "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP\ZIP_Backup_Log_%date:~-4,4%_%date:~-10,2%_%date:~-7,2%.rar" "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\Logs"
        NET USE \\IP\IPC$ /u:IP\username password
        ROBOCOPY "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%\ZIP"  "\\IP\Backup Folder" /z /MIR /unilog+:"C:\backup_log_%date:~-4,4%%date:~-10,2%%date:~-7,2%.log"
        NET USE \\172.20.10.103\IPC$ /D
        RMDIR /S /Q "C:\Temp Backup_%date:~-4,4%%date:~-10,2%%date:~-7,2%"
    
    0 讨论(0)
  • 2020-12-12 20:27

    I see a lot of answers suggesting the use of xcopy. But this is unnecessary. As the question clearly mentions that the author wants THE CONTENT IN THE FOLDER not the folder itself to be copied in this case we can -:

    copy "C:\Folder1" *.*  "D:\Folder2"
    

    Thats all xcopy can be used for if any subdirectory exists in C:\Folder1

    0 讨论(0)
  • 2020-12-12 20:31

    RoboCopy did not work for me, and there are some good solutions here, but none explained the XCopy switches and what they do. Also you need quotes in case your path has spaces in it.

    xcopy /i /e "C:\temp\folder 1" "C:\temp\folder 2"

    Here is the documentation from Microsoft:

    XCopy MS Documentation

    /s: Specifies to include subdirectories. Excludes empty subdirectories
    /e: Copies all subdirectories, even if they are empty
    /i: specifies the destination is a folder (Otherwise it prompts you)
    
    0 讨论(0)
  • 2020-12-12 20:34

    If you have robocopy,

    robocopy C:\Folder1 D:\Folder2 /COPYALL /E
    

    otherwise,

    xcopy /e /v C:\Folder1 D:\Folder2
    
    0 讨论(0)
提交回复
热议问题