Robocopy: copy drive root directory creates Hidden backup folder

franklin-xy 26 Reputation points
2022-02-17T21:04:52.667+00:00

Windows 10 Home 21H2 19044.1526, 64-bit
Robocopy 10.0.19041.1266
Run Robocopy via .bat file, Run as Administrator.

Hello:

When I use Robocopy to copy the root directory of a drive (D:) to a folder (non-root directory) on an external drive, the resulting destination folder is Hidden. I believe that's because the root drive has System and Hidden attributes.
How can I prevent System and Hidden attributes from being applied to the destination folder?

My testing (I removed options for multi-threads, retries, logging, etc., to make it easier for you folks to read.):

SET options=/MIR /A-:RSHA /XA:SH /XJ /XD "$RECYCLE.BIN" "System Volume Information" /XF DESKTOP.INI
ROBOCOPY "D:" "Y:\Backups\Test" %options%

/A-:RSHA does not work to prevent the destination folder from being hidden, though I read that it should work.
So, I added /COPY:DT /DCOPY:DT to options so as not to backup properties and attributes:

SET options=/COPY:DT /DCOPY:DT /MIR /A-:RSHA /XA:SH /XJ /XD "$RECYCLE.BIN" "System Volume Information" /XF DESKTOP.INI
ROBOCOPY "D:" "Y:\Backups\Test" %options%

/COPY:DT /DCOPY:DT did not help, as destination backup folder is still created as hidden.

I can run ATTRIB command after the backup, as in:

attrib -s -h "Y:\Backups\Test"

This does unhide the hidden directory, but I would prefer to find a way to prevent Robocopy from hiding the backup in the first place.

How can I prevent System and Hidden attributes from being applied to the destination folder?

Windows for business | Windows Client for IT Pros | Devices and deployment | Configure application groups
Windows for business | Windows Server | User experience | Other
Windows for business | Windows Client for IT Pros | User experience | Other
0 comments No comments
{count} vote

2 answers

Sort by: Most helpful
  1. MotoX80 36,401 Reputation points
    2022-02-18T14:43:34.89+00:00

    How about using Powershell to only copy the subfolders?

    $Source = "D:\"                  # Must have trailing slash 
    $Dest = "Y:\Backups\Test\"          # Must have trailing slash 
    $TopDirs = Get-ChildItem -Path $source -directory
    $Options = '/COPY:DT /DCOPY:DT /Mir  /XA:SH /XJ  /XF DESKTOP.INI /l'       # Note /l switch for testing
    foreach ($Dir in $TopDirs) {
        $cmd = "robocopy.exe $Source$Dir $Dest$Dir $Options" 
        $cmd                      # Display the command that we would execute. 
        #Invoke-Expression $cmd   # Uncomment to actually Execute the robocopy command 
        #return                   # uncomment to only copy the first folder during initial testing
    }
    
    1 person found this answer helpful.

  2. Michal Šovčík 0 Reputation points
    2024-10-21T11:59:18.0866667+00:00

    /A switch did not help in my case. Only after /COPY and /DCOPY switches were removed, destination folders remained not hidden after robocopy.

    If folder is already hidden, you have to clear the attribute first with: > attrib -s -h \path\folder

    0 comments No comments

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.