Home > database >  Prevent Robocopy to default folder mode to d--hs
Prevent Robocopy to default folder mode to d--hs

Time:04-22

Intro

I am making backups of some USB drives using a script that uses Robocopy. It places the files on the USB onto an external hard drive in a folder named by the date of the backup. When I looked at the external hard drive in file explorer I couldn't find the backup. However, when doing 'dir -force' in PowerShell I can see the files are definitely there:Dir -force snippit Notice that the folders I am missing are in Mode d--hs.

Question

How do I prevent Robocopy from copying to a mode d--hs folder and instead to a d----?

Code

$Day = "{0:yyyy-MM-dd}" -f (get-date)

$usb1 = 'E:'
$usb2 = 'F:'
$usb3 = 'H:'
$usb4 = 'I:'
$usb5 = 'J:'
$usb6 = 'K:'

$usblist = $usb1,$usb2,$usb3,$usb4,$usb5,$usb6

$usblist | ForEach-Object -Parallel {
$usb = $_
$Day = "{0:yyyy-MM-dd}" -f (get-date)
Robocopy /z /r:3 /w:3 /E "$usb" "U:\$Day" *.png /S |Out-Null|  Out-Default  
Robocopy /z /r:3 /w:3 /E "$usb" "X:\$Day" *.png /S |Out-Null| Out-Default 
Robocopy /z /r:3 /w:3 /E "$usb" "Y:\$Day" *.png /S |Out-Null| Out-Default 
}-ThrottleLimit 6

System info

OS: Windows 11

Powershell: 7.3.0-preview.3

CodePudding user response:

Just so there is an answer to the thread.

Like @Lee_Daily mentioned in the comments under my question using e.g. c: causes this issue. Moving the files first to a different folder first is a solution.

Another solution I found is just removing the HS using the attrib command.

attrib -H -S Y:\*.* /S /D

A similar issue

While looking into this, I also found this thread that may be helpful: After Robocopy, the copied Directory and Files are not visible on the destination Drive

Final Code

$Day = "{0:yyyy-MM-dd}" -f (get-date)

$usb1 = 'E:'
$usb2 = 'F:'
$usb3 = 'H:'
$usb4 = 'I:'
$usb5 = 'J:'
$usb6 = 'K:'

$usblist = $usb1,$usb2,$usb3,$usb4,$usb5,$usb6

$usblist | ForEach-Object -Parallel {
$usb = $_
$Day = "{0:yyyy-MM-dd}" -f (get-date)
Robocopy /z /r:3 /w:3 /E "$usb" "U:\$Day" *.png /S |Out-Null| Out-Default  
Robocopy /z /r:3 /w:3 /E "$usb" "X:\$Day" *.png /S |Out-Null| Out-Default 
Robocopy /z /r:3 /w:3 /E "$usb" "Y:\$Day" *.png /S |Out-Null| Out-Default 
}-ThrottleLimit 6

attrib -H -S U:\*.* /S /D
attrib -H -S X:\*.* /S /D
attrib -H -S Y:\*.* /S /D
  • Related