Robocopy cannot copy files when I specify which folders to copy

523311 40 Reputation points
2023-07-27T04:40:46.5566667+00:00

https://answers.microsoft.com/en-us/windows/forum/all/why-robocopy-only-copy-directories-but-not-files/6dbeb8e7-f139-422a-aafe-19bd292c9297?page=1e-19bd292c9297?page=1

I have an additional question on this thread, the consequence still doesn't make sense for me.

Regard there are folder a b c d, inside of each folder, a' b' c' d' folder exists and inside there, there are a" b" c" d" files each.

C:\folder\a\a'\a" c:\folder\b\b'\b" c:\folder\c\c'\c" c:\folder\d\d'\d"

When I

Robocopy "c:\folder" "destination-path" "a" "b" "c" /e /copy:dat

, then only 'of structures' only directories copied, no files copied with that process.

Why is this happening,

And

If I put the origin and destination of the specific folders and run the command in sequence for each folder, nothing wrong happening?

Azure Files
Azure Files
An Azure service that offers file shares in the cloud.
1,213 questions
Windows Server Backup
Windows Server Backup
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Backup: A duplicate copy of a program, a disk, or data, made either for archiving purposes or for safeguarding valuable files from loss should the active copy be damaged or destroyed.
464 questions
Windows Server Infrastructure
Windows Server Infrastructure
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Infrastructure: A Microsoft solution area focused on providing organizations with a cloud solution that supports their real-world needs and meets evolving regulatory requirements.
526 questions
Windows Server Storage
Windows Server Storage
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Storage: The hardware and software system used to retain data for subsequent retrieval.
642 questions
Windows Server Migration
Windows Server Migration
Windows Server: A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.Migration: The process of making existing applications and data work on a different computer or operating system.
413 questions
0 comments No comments
{count} votes

Accepted answer
  1. Sumarigo-MSFT 44,906 Reputation points Microsoft Employee
    2023-07-27T09:53:41.69+00:00

    @523311 Welcome to Microsoft Q&A Forum, Thank you for posting your query here!

    The behavior you're experiencing is because of how Robocopy interprets the source and destination paths when multiple folder names are provided as arguments.

    Robocopy only copies the directory structure when you use the /e flag. To copy files, you need to use the /s flag.
    If you run the command for each folder separately, it should work as expected. However, it is recommended to use the /MT flag to enable multi-threaded copying, which can significantly improve performance.

    When you run the command:

    	Robocopy "c:\folder" "destination-path" "a" "b" "c" /e /copy:dat
    

    Robocopy interprets "a" "b" "c" as file names rather than folder names, which results in copying only the folder structure without the files. This is because Robocopy treats any argument that does not end with a backslash () as a file name. So, in this case, it's not recognizing "a", "b", and "c" as folder names.

    To copy the entire folder structure along with files and subdirectories, you should use wildcards to specify the folders. Here's how you can achieve that:

    Robocopy "c:\folder" "destination-path" "a*" "b*" "c*" /e /copy:dat
    
    

    By using "a*", "b*", and "c*" with asterisks as wildcards, you are telling Robocopy to match any folder that starts with "a", "b", or "c" respectively, and copy their contents along with subdirectories and files.

    Regarding your second question, if you run the Robocopy command separately for each folder, specifying the individual folder paths as sources and destination, it should work correctly because Robocopy will treat each argument as a separate folder path and copy their contents along with files and subdirectories.

    Robocopy "c:\folder\a" "destination-path\a" /e /copy:dat
    Robocopy "c:\folder\b" "destination-path\b" /e /copy:dat
    Robocopy "c:\folder\c" "destination-path\c" /e /copy:dat
    
    

    This should , Robocopy will correctly copy the folder structures along with files and subdirectories from each specified folder to the corresponding destination folder.

    For detailed information on RoboCopy : https://video2.skills-academy.com/en-us/azure/storage/files/storage-files-migration-robocopy

    Additional inforamtion: For testing you can use Azcopy tool
    Robocopy examples

    If you still find any difficulties, please let me know I would like to closer on this issue


    Please do not forget to "Accept the answer” and “up-vote” wherever the information provided helps you, this can be beneficial to other community members.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful