xlong.cmd

It is possible to create very long filenames/pathnames on NTFS that exceed the Windows API limit. This typically happens when a folder which is part of a deep hierarchy gets renamed. Very long filenames will often create errors in applications that attempt to open them (even Windows Explorer.)

The script below will list any files that exceed this limit.

@Echo off
Setlocal EnableDelayedExpansion
:: Report all file / folder paths that exceed the 256 character limit
If {%1}=={} Echo Syntax: XLong DriveLetter&goto :EOF
Set wrk=%1
Set wrk=%wrk:"=%

For /F "Tokens=*" %%a in ('dir %wrk% /b /s /a') do (
 set name=%%a
 if not "!name:~255,1!"=="" echo Extra long name: "%%a"
)
Endlocal

Examples

c:\> xlong D:
c:\> xlong S:\workgroups\

The maximum Windows API MAX_Path is 260 characters, subtract 3 characters for the drive and colon: and 1 character for a terminating NULL and you have a maximum 256 characters that can be used for the pathname.

All .Net applications enforce the Windows API pathname limit including Windows Explorer and PowerShell.

To access very long paths use Robocopy, SUBST or the \\?\UNCPATH\ syntax.

“This report, by its very length, defends itself against the risk of being read” ~ Winston Churchill

Related

Which.cmd - Display full path to any command
Bash equivalent:
find . | awk '{print length($0) " " $0}' | sort -n | tail -n 15


© Copyright SS64.com 1999-2013
Some rights reserved