Share via

ROBOCOPY fails copying files from source root

Anonymous
2023-03-08T10:24:39+00:00

When copying files from source root, it seems that ROBOCOPY see the file(s) as directories and the resoult is, that the filename become a directoiry name on target

Logfile says:

2023/03/08 11:16:09 ERROR 267 (0x0000010B) Accessing Source Directory \XXXXXXXXXX\mdt$\Placer IKKE l›se filer i hovedshare - Vedr_backup_VIGTIGT.txt\

The directory name is invalid.

How can I prevent that

My code:

$FileName = (Get-Date).tostring("MM-dd-yyyy---HH-mm-ss")

$oldpaths = Get-ChildItem "\XXXXXXXXXX\mdt$\*"

$newpath = 'Q:\CTXMDT'

Set-Location $newpath

foreach($oldpath in $oldpaths)

{

    $newpath1 = $newpath + $oldpath.Name  

    mkdir $newpath1 -ErrorAction Ignore > $null

      robocopy $oldpath $newpath1 /Z /MT:16 /MIR /W:0 /R:0 /V /TS /FP /PF /E /FFT /XO /SEC /XD ".snapshots" /XD "$RECYCLE.BIN" | Out-File D:\Logfiler\XXXXXXXXXX_MDT"$FileName MDT.log" -Append

    Write-Host "$oldpath has been copiet to $newpath1"

}

Best regards

MACH

Windows for home | Windows 10 | Files, folders, and storage

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

3 answers

Sort by: Most helpful
  1. Anonymous
    2023-03-08T12:10:34+00:00

    That's a sightly different command you are running manually, as the $oldpath variable will take each file individually from a list of $oldpaths in the foreach loop.

    In the powershell you shouldn't need the /MIR flag as this is for a full directory tree to another location. In your script you are cycling one file at a time

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2023-03-08T12:01:49+00:00

    Hi Elise

    Thanks for replying om my problem.....

    Well same resoulth with robocopy "$oldpath"

    I just tested my robocopy command in a commandline, and that works fine

    (  robocopy \XXXXXXXX\mdt$\ Q:\CTXMDT\ /Z /MT:16 /MIR /W:0 /R:0 /V /TS /FP /PF /E /FFT /XO /SEC /XD ".snapshots" /XD "$RECYCLE.BIN" )

    So for some reason, - Powershell is the challange and not Robocopy as I expected...

    The funny thing is, - that if the file allready excist on target, - my powershell script does not create a folder as I would expect....

    Best regards...

    Malte C",)

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2023-03-08T11:02:20+00:00

    Hi, I'm Elise, and I'd be happy to help with your issue.

    Try change robocopy $oldpath to robocopy "$oldpath"

    Please let me know if you need any further assistance.

    Kind Regards,

    Elise

    Was this answer helpful?

    0 comments No comments