0

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

Olaf
  • 146
  • 1
  • 8
  • it is unusual NOT to specify the source dir ... you just use `c:` instead of `c:\`. have you tried giving a source _dir_ instead of just a _drive_? – Lee_Dailey Apr 19 '22 at 12:34
  • The problem is that if I do c: instead of `c:`, the code doesn't run it just changes to the last drive specified in the USB list. There is no real source dir on the drives, I get them with the files directly on the drive. – Olaf Apr 19 '22 at 12:46
  • It is definitely related to your suggestion @Lee_Dailey . I have tried putting the files into a sub folder, and then copying it over. Now it does NOT create a system file. – Olaf Apr 19 '22 at 13:00
  • 1
    the root dir of any drive - especially the system or boot drive - is often protected. there are MANY apps that have problems saving to the root of c:, for instance. ///// i am glad that you found a workable fix! [*grin*] – Lee_Dailey Apr 19 '22 at 13:11

1 Answers1

0

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
Olaf
  • 146
  • 1
  • 8