I would like to know if anyone has devised an efficient way in NT batch of computing path lengths in a given folder. This is necessary to identify files and folders which won't successfully archive to optical media, which continue to enforce 260-character path limits though NTFS now supports path lengths of up to 32,767 characters.
I have been using a batch script which works by echoing each full path to a file, measuring the size of the file, and subtracting 2 to get the character count in the path. This works well for low file counts, but takes a long time to finish for high file counts. Ideally, I would like something that works almost as fast as the 'dir' command itself.
@ECHO OFF SETLOCAL ENABLEDELAYEDEXPANSION set Limit=%~1 echo Paths being found which exceed !Limit! echo ====================================== type NUL > "!temp!\tabulator.txt" FOR /F "tokens=1 delims=" %%A IN ('dir /o:-n /b /s') DO ( set Test=%%A call set Test=%%Test:~%Limit%%%. IF !Test! NEQ . ( type NUL > "!temp!\pathlengthdeterminationtemp.txt" echo %%A > "!temp!\pathlengthdeterminationtemp.txt" FOR /F "tokens=1 delims=" %%H IN ('dir /s /o /b "!temp!\pathlengthdeterminationtemp.txt"') DO set StrLen=%%~zH del "!temp!\pathlengthdeterminationtemp.txt" set /a StrLen=!StrLen!-2 echo !StrLen!,%%A>> "!temp!\tabulator.txt" ) ) sort "!temp!\tabulator.txt" /O "!temp!\tabulator1.txt" del "!temp!\tabulator.txt" TYPE "!temp!\tabulator1.txt" del "!temp!\tabulator1.txt" ENDLOCAL