I've written a script to read files and generate their hashes to verify if large folders have been copied correctly. However, I'm hitting a roadblock with the 260-character limit for file paths. I'd really appreciate any suggestions on how to bypass this issue. Here's some of my code to give you context: I initialize some paths and attempt to enumerate files within a specified directory using `Get-ChildItem`. The script is designed to handle errors and log them, but it's mainly focused on the hashing process. Any help would be great!
5 Answers
By the way, you might want to adjust where you're adding content to your CSV. Instead of adding each entry one at a time, accumulate a bunch of them and then write them all at once. For CSV files, consider using `Export-Csv` for better efficiency.
You might want to prepend `\?` to your file paths. This allows Windows to recognize long paths, which can help you bypass that pesky 260-character limit.
Side note, your formatting could improve—using inline code can make it messy. Consider copying your code directly from your PowerShell editor to format it better before pasting.
Make sure you’ve enabled 'Long Paths' in your Windows settings. It might help with your issue.
Just a heads-up, enabling that setting only works if the program supports long paths. PowerShell 5.1 does, but PowerShell 7.x doesn't.
I'm pretty sure it's enabled, but how can I double-check it?
Yes, it's definitely enabled.
Are you using something like robocopy to handle your files? If you run it, it doesn't impose the same path limits as other methods.
This isn't for copying files; it's just for verifying the hash against the original files to check for any changes.

I've tried that already! The code is supposed to scan all folders, but there are just some files that exceed the limit.