I have a script that I am running which is supposed to do just a simple copy of 2 folders from a system drive to an external USB HDD.
Script is attached.
This is the error I am getting and it seems to be halting the script after hitting this error a few times. It seems pretty pathetic that Microsoft would even allow you to create a path that would be too long for their own tool to handle. Am I doing something wrong?
Copy-Item : The specified path, file name, or both are too long. The fully qualified file name must be less than 260 characters, and the directory name must be less
than 248 characters.
$SourceDir1 = "D:\Data\Users\*"
$SourceDir2 = "D:\Data\Sharing\*"
$Directory1 = New-Item -Name $((Get-Date).ToString('dd.MM.yyyy')) -Type Directory -Path "f:\Users\"
$Directory2 = New-Item -Name $((Get-Date).ToString('dd.MM.yyyy')) -Type Directory -Path "f:\Sharing\"
copy-item $SourceDir1 -destination $Directory1 -recurse
copy-item $SourceDir2 -destination $Directory2 -recurse