Hi Readers! This article may help you to find the folder or file name length using the PowerShell script.
Normally, this script will help you when you have a large number of child folders or files under the parent folder.
Recently, I have faced one issue with OneDrive synchronization and got an error like “File Name too Long” but we don’t know which child folder has the long path or long file name. So, I just executed the below script to identify the long file name and trimmed it to the appropriate file name size.
PowerShell Script
- #Getting the parent FilePath
- $path = Read-Host “Enter the Path”
- #Listing the child folder and path size in descending order
- Dir $path -file -recurse | select Fullname,@{Name=”NameLength”;Expression={$_.fullname.length}} | sort NameLength -Decending