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
In PS you would just do New-PSDrive and skip the SMB share.
Bonus: You can call it whatever you like, not limited to a letter.
I use that for my git repos, where I have a PSDrive named for each project so I can simply
pushd SomeProject:and I'm there. They only exist in the scope of a powershell session though, which is a bummer.Or there are always symlinks, hardlinks, junctions, or drive mount reparse points since like Windows XP-era NTFS for most of those and Vista for the rest. Directory too long and no other option for long paths? Just make a junction to it in the root of the drive. Junctions are something NTFS on Windows can do that most file systems and operating systems can't - basically hard links for directories. And just like a file hard link, they are a canonical name of the path, unlike symlinks, which have to be canonicalized by the system to get the actual target.