top of page

How to Find File and Folder Path Lengths Recursively using PowerShell (Get-LongPaths)

  • Writer: Chris Keim
    Chris Keim
  • May 9, 2022
  • 1 min read

Sometimes users like to get wordy with file paths. This is usually no problem especially if you enable long file path support. But, what if you are using a program that doesn't support long file path names? Easy, just find the long file paths and shorten them. Easier said then done when working with a file server. This script recursively finds paths over a specific length recursively.


Syntax

Get-LongPaths -Path <string> -Length <integer>


Description

The Get-LongPaths cmdlet finds all paths recursively over a specified length and outputs to a grid view.


Examples

Example 1: Find all paths over 256 characters recursively starting with the root directory D:\Shares.

Example 2: Find all paths over 100 characters recursively starting with the root directory D:\Departments

Parameters


-Path (Mandatory)

Specifies the root path to search recursively.

-Length (Optional)

Specifies the path character limit before the path is reported by the function.


PowerShell Script


1 Comment


lewisanna2025
Jun 09, 2025

🛠 PowerShell Script: Get-LongPaths

This script scans a directory recursively and lists files or folders where the full path length exceeds a specified limit (default is 260).

powershell

CopyEdit

function Get-LongPaths { param ( [string]$StartPath = "C:\Your\Directory\Here", [int]$MaxLength = 260 ) Write-Host "Scanning paths under: $StartPath" -ForegroundColor Cyan Write-Host "Checking for paths longer than $MaxLength characters..." -ForegroundColor Cyan $items = Get-ChildItem -Path $StartPath -Recurse -Force -ErrorAction SilentlyContinue $longPaths = $items | Where-Object { $_.FullName.Length -gt $MaxLength } foreach ($item in $longPaths) { $length = $item.FullName.Length Write-Host "$length characters: $($item.FullName)" -ForegroundColor Yellow } Write-Host "`nTotal long paths found: $($longPaths.Count)" -ForegroundColor Green return $longPaths

Like

Subscribe

©2018 by ChristopherKeim. Proudly created with Wix.com

bottom of page