PowerShell:
((Get-ChildItem -Recurse).FullName | Measure-Object -Property Length -Maximum).Maximum
Command line:
powershell -exec Bypass -c "((dir -rec).FullName | measure Length -max).Maximum"
Edit
related to error: Get-ChildItem : The specified path, file name, or both are too long
: read Maximum Path Length Limitation and related [PowerShell]-tagged StackOverflow threads.
PS D:\PShell> ((Get-ChildItem "D:\odds and ends" -Directory -Recurse).FullName | Measure-Object -Property Length -Maximum).Maximum
242
PS D:\PShell> ((Get-ChildItem "D:\odds and ends" -Recurse -ErrorAction SilentlyContinue).FullName | Measure-Object -Property Length -Maximum).Maximum
242
Note that -ErrorAction SilentlyContinue
in above command merely suppresses displaying of error messages. However, I know that the latter 242
value returned is wrong.
My workaroud applies cmd /C dir /B /S
instead of (Get-ChildItem -Recurse).FullName
as follows:
PS D:\PShell> $x = (. cmd /C dir /B /S "D:\odds and ends")
PS D:\PShell> $y = ( $x | Measure-Object -Property Length -Maximum).Maximum
PS D:\PShell> $y
273
PS D:\PShell> $z = $x | Where-Object { $_.Length -gt 260 }
PS D:\PShell> $z.GetTypeCode()
String
PS D:\PShell> $z
D:\odds and ends\ZalohaGogen\WDElements\zalohaeva\zaloha_honza\Music\Jazz\!Kompilace\Saint Germain des Pres Cafe Vol. 1 to 8 - The Finest Electro Jazz Complication\Saint Germain Des Pres Cafe Vol. 7 - The Finest Electro Jazz Complication\CD 1\Configuring and Using Inte.txt
PS D:\PShell>