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
1
u/TheThirdHippo Nov 26 '25
Not a problem. I’m no PS guru, I follow this sub to get everyone else’s ideas and have had some great tips from it. I do use a combination of what I’ve learnt in PS, mixed with my ancient DOS knowledge and a sprinkling of Unix/Linux that has made its way over. I hope my ‘No, I mean’ didn’t come across harsh, it was meant in a polite way