Find Files by Length of Filename Using Powershell

How do I find files with a path length greater than n characters …

In windows you may get the file name length issue as like below in processing files like copy, move, delete, etc.

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.

In this scenario, you may want to find the files with file path length is greater than or equal to 260 char or particular length.

You can use below Powershell script to find files by length of filename.


<# Get-ChildItem -Path "C:\Folder\Path\To\Check\The\File\Length\" -Recurse -File |Where-Object {$_.FullName.Length -ge 260 } | %{$_.FullName}
   % is alias of ForEach-Object #>

Get-ChildItem -Path "C:\Folder\Path\To\Check\The\File\Length\" -Recurse -File |Where-Object {$_.FullName.Length -ge 260 } | ForEach-Object{$_.FullName}

You can update the file length in above script which you want to find

If you want the result to a text file, you can pass the result to a text file using a pipe symbol.


Get-ChildItem -Path "C:\Folder\Path\To\Check\The\File\Length\" -Recurse -File |Where-Object {$_.FullName.Length -ge 260 } | ForEach-Object{$_.FullName} | C:\Temp\Result.txt

comments powered by Disqus
Next
Previous

Related