01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 | $sourceDirectory = 'D:\SMBSHARE\LONGPATH' $destinationDirectory = '\\FILESERVER\LONGPATH' function copyFolderWithLongNames( $sourceDirectory , $destinationDirectory ){ $sourceParent = split-path $sourceDirectory -parent $sourceChild = split-path $sourceDirectory -leaf $destinationParent = split-path $destinationDirectory -parent $destinationChild = split-path $destinationDirectory -leaf $maxFolderLength =248 if ( $sourceParent .length -le $maxFolderLength -and $destinationParent .length -le $maxFolderLength ){ $sourceJunction = 'C:\Source' $destinationJunction = 'C:\Destination' cmd /c mklink /J $sourceJunction $sourceParent # Local volumes are required as Source Directory cmd /c mklink /D $destinationJunction $destinationParent cmd /c robocopy "$sourceJunction\$sourceChild" "$destinationJunction\$destinationChild" /copyall /E /R:0 /Z /NP [io.directory] ::Delete( $sourceJunction ) [io.directory] ::Delete( $destinationJunction ) } # Other methods that could also work #robocopy "\\?$sourceDirectory" "\\?$destinationDirectory" # OR #Subst X: $sourceDirectory #Subst Y: $destinationDirectory #robocopy X:\ Y:\ /copyall /E /R:0 /Z /NP #subst X: /d #subst Y: /d } copyFolderWithLongNames $sourceDirectory $destinationDirectory |
Categories: