Find long folder and file paths with PowerShell

1

Often during server migrations we come across an issue when using Windows Sync Centre to sync up staff devices in that the path limit is 260 chars, using this simple one line we are able to find the paths that are too long for Sync Centre to sync up and rename them.

Once the folders have been renamed you can use takeown and icacls to set the permissions see here.

Open an Administrative PowerShell window, CD to the directory in question and run the following command.

Get-ChildItem -Recurse -Force -ErrorAction SilentlyContinue | Where-Object {$_.FullName.Length -gt 250}

NB – You can address long file paths with icacls using the below

Prefixing my path with the string “\\?\” as below, allows icacls to successfully address longer file paths.

icacls “\\?\M:\Archive\*” /c /t /reset

When my script runs using this prefix, it now runs correctly, and successfully processes all files without error….SUCCESS!!! This also works with UNC paths.

Found priceless insights in this blog? Support the author’s creativity – buy them a coffee!

1 thought on “Find long folder and file paths with PowerShell

Leave a Reply

Your email address will not be published. Required fields are marked *