Robocopy: copy drive root directory creates Hidden backup folder

franklin-xy 21 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 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
10,744 questions
Windows Server
Windows Server
A family of Microsoft server operating systems that support enterprise-level management, data storage, applications, and communications.
12,232 questions
Windows 10 Security
Windows 10 Security
Windows 10: A Microsoft operating system that runs on personal computers and tablets.Security: The precautions taken to guard against crime, attack, sabotage, espionage, or another threat.
2,776 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. MotoX80 32,086 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.