Find The Length Of Path Using The PowerShell

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

  1. #Getting the parent FilePath  
  2. $path = Read-Host “Enter the Path”  
  3. #Listing the child folder and path size in descending order  
  4. Dir $path -file -recurse | select Fullname,@{Name=”NameLength”;Expression={$_.fullname.length}} | sort NameLength -Decending  

PowerShell

Next Recommended Reading
Disk Cleanup Using Powershell Scripts