I am trying to handle errors when scanning through folders. Let\'s say I have something like:
Get-ChildItem $somepath -Directory | ForEach-Object {
if(err
If you can install a non-ancient PowerShell version (3.0 or newer), simply prepend the path with \\?\
to overcome the 260-character limit for full path:
Get-ChildItem "\\?\$somepath" | ForEach {
# ............
}
You could try ignoring the files longer 260 characters by using the Where-Object
cmdlet.
Get-ChildItem $somepath -Directory -ErrorAction SilentlyContinue `
| Where-Object {$_.length -lt 261} `
| ForEach-Object { Write-Host $_.BaseName }
Or you could use the following (Ref).
cmd /c dir $somepath /s /b | Where-Object {$_.length -lt 261}