How to copy specific files using Robocopy

Mayur Rastogi 20 Reputation points
2025-01-24T15:53:17.5933333+00:00

I need to copy few specific files from one Physical Server to another. I used below command but it prompted the error:-

  1. robocopy \msXXXXX\N$\AXXX\AXXX1.lbl \msXXXXXX\M$\AXXX /E /Z /COPY:DATSOU /SECFIX /R:3 /LOG:C:\Log\robcpy.log

Error:2025/01/24 10:33:29 ERROR 267 (0x0000010B) Accessing Source Directory \msXXXX\N$\AXXX\AXXXX.lbl\

The directory name is invalid.

As you can see in the syntax I have not specified '/' but still its reflecting in the error.

  1. Additionally, If I want to copy files with specific name of any format such as A4*.*, where * with file in the request should be for anything after A4. it prompts below error.

ERROR : Invalid Parameter #1 : "\ms00010890p\N$\A4110106\A506W1.*"

Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
13,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.
439 questions
0 comments No comments
{count} votes

Accepted answer
  1. MotoX80 35,416 Reputation points
    2025-01-25T14:59:16.4833333+00:00

    If you look at the robocopy help, you will see that the first parameter is the source folder, the second parameter is the destination folder, and the subsequent parameters are the files that you want to copy. "[file [file]...]"

    User's image

    Assuming that AXXX1.lbl is the name of a file, you would specify it like this.

    robocopy \\msXXXXX\N$\AXXX\ \\msXXXXXX\M$\AXXX\ AXXX1.lbl 
    
    
    

    You have included the /e switch which is:

    /E :: copy subdirectories, including Empty ones.
    

    If you are attempting to copy specific files, then there is no reason to copy subdirectories.

    I would also caution you on copying file security if you are only copying files. From my experience, setting security on individual files is a bad idea. You should always have files inherit the permissions from the folder that they reside in.

    Explanation: Office apps like Excel and Word do not save updates back to the original file. They create a temporary file, save the data, delete the original file, and then rename the temp file back to the original name. So, if you have unique permissions on a file, they will be lost when a user updates the file.

    If the AXXX folder does not exist on the destination, then copying security would make sense. You might want to check the permissions after you run the copy to verify that any inherited permissions are copied/set correctly.

    1 person found this answer helpful.

1 additional answer

Sort by: Most helpful
  1. Michael Taylor 56,781 Reputation points
    2025-01-24T17:30:08.3266667+00:00

    UNC paths are of the form \\server\share\path. Given your post it appears you are not specifying the UNC path correctly so it is seeing it as a local directory. Try something like this:

    robocopy \\msXXXXX\N$\AXXX\AXXX1.lbl \\msXXXXXX\M$\AXXX /E /Z /COPY:DATSOU /SECFIX /R:3 /LOG:C:\Log\robcpy.log
    

    Of course the account running this command needs both share permission and file system permission. Since you're using the hidden shares that probably means you need to be an admin. If that isn't possible then consider creating regular network shares on the machines and granting permissions to the account running this command.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.