r/PowerShell • u/Key-Research-6708 • Nov 25 '25
Question File Paths too long
I want to compare 2 directories contents to make sure a robocopy completed successfully, and windows is saying the filepaths are too long, even after enabling long files paths in GPEdit and in Registry and putting \\?\ or \?\ before the filepaths in the variables is not working either. is there any way around this issue?:
script:
$array1 = @(Get-ChildItem -LiteralPath 'C:\Source\Path' -Recurse | Select-Object FullName)
$array2 = @(Get-ChildItem -LiteralPath 'C:\Destination\Path' -Recurse | Select-Object FullName)
$result = @()
$array2 | ForEach-Object {
$item = $_
$count = ($array1 | Where-Object { $_ -eq $item }).Count
$result += [PSCustomObject]@{
Item = $item
Count = $count
}
}
Error received with above script:
Get-ChildItem : 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.
error with \\?\ before file paths: Get-ChildItem : Illegal characters in path.
View all comments
Show parent comment
2
u/dodexahedron Dec 01 '25
This is the way, if you can do it all inside the powershell session. What it is really doing is translating the paths on the fly for you, though. So, if the FS or the OS config is not long name friendly, many powershell commandlets may work, but some other binaries may not be terribly happy if they need to know anything about such a path or were just written poorly.