Fast NT batch script for determining path lengths in a folder












2















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









share|improve this question






















  • Does it ave to be batch? PowerShell is the modern equivalent and does all sorts of great thing efficiently.
    – Austin T French
    Nov 18 '13 at 15:12












  • There are indeed PowerShell scripts to determine path length: stackoverflow.com/questions/12697259/… However, I'm looking for a solution that doesn't require launching the PowerShell console or changing to the folder I am interested in. The 'pathlength' script I quoted above is in my Windows path, so I can run it simply by opening a command window in the folder I am interested in.
    – J N Winkler
    Nov 18 '13 at 15:40


















2















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









share|improve this question






















  • Does it ave to be batch? PowerShell is the modern equivalent and does all sorts of great thing efficiently.
    – Austin T French
    Nov 18 '13 at 15:12












  • There are indeed PowerShell scripts to determine path length: stackoverflow.com/questions/12697259/… However, I'm looking for a solution that doesn't require launching the PowerShell console or changing to the folder I am interested in. The 'pathlength' script I quoted above is in my Windows path, so I can run it simply by opening a command window in the folder I am interested in.
    – J N Winkler
    Nov 18 '13 at 15:40
















2












2








2








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









share|improve this question














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






windows command-line batch






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 18 '13 at 15:08









J N Winkler

112




112












  • Does it ave to be batch? PowerShell is the modern equivalent and does all sorts of great thing efficiently.
    – Austin T French
    Nov 18 '13 at 15:12












  • There are indeed PowerShell scripts to determine path length: stackoverflow.com/questions/12697259/… However, I'm looking for a solution that doesn't require launching the PowerShell console or changing to the folder I am interested in. The 'pathlength' script I quoted above is in my Windows path, so I can run it simply by opening a command window in the folder I am interested in.
    – J N Winkler
    Nov 18 '13 at 15:40




















  • Does it ave to be batch? PowerShell is the modern equivalent and does all sorts of great thing efficiently.
    – Austin T French
    Nov 18 '13 at 15:12












  • There are indeed PowerShell scripts to determine path length: stackoverflow.com/questions/12697259/… However, I'm looking for a solution that doesn't require launching the PowerShell console or changing to the folder I am interested in. The 'pathlength' script I quoted above is in my Windows path, so I can run it simply by opening a command window in the folder I am interested in.
    – J N Winkler
    Nov 18 '13 at 15:40


















Does it ave to be batch? PowerShell is the modern equivalent and does all sorts of great thing efficiently.
– Austin T French
Nov 18 '13 at 15:12






Does it ave to be batch? PowerShell is the modern equivalent and does all sorts of great thing efficiently.
– Austin T French
Nov 18 '13 at 15:12














There are indeed PowerShell scripts to determine path length: stackoverflow.com/questions/12697259/… However, I'm looking for a solution that doesn't require launching the PowerShell console or changing to the folder I am interested in. The 'pathlength' script I quoted above is in my Windows path, so I can run it simply by opening a command window in the folder I am interested in.
– J N Winkler
Nov 18 '13 at 15:40






There are indeed PowerShell scripts to determine path length: stackoverflow.com/questions/12697259/… However, I'm looking for a solution that doesn't require launching the PowerShell console or changing to the folder I am interested in. The 'pathlength' script I quoted above is in my Windows path, so I can run it simply by opening a command window in the folder I am interested in.
– J N Winkler
Nov 18 '13 at 15:40












4 Answers
4






active

oldest

votes


















2














To check the length of an environment variable, you can do something similar to this:



set a=1234567890123

if [%a:~0,-12%]== (
echo a is shorter than 13
) else (
echo %a% is longer than 12
)


Expression %a:~0,-12% returns all but the last 12 characters of variable a.



Enter set /? to get details.



However, I am not sure if this also work under NT. I have tested it as CMD script under Windows 7.






share|improve this answer





















  • Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
    – dbenham
    Nov 18 '13 at 16:45










  • Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
    – Axel Kemper
    Nov 19 '13 at 18:42



















0














There is no built-in command for determining the length of a string in a batch file. It necessarily involves ugly hacks like writing to a file. However, it is relatively easy to check whether a string exceeds a fixed length such as the 260 character limit. The following script grabs a 260 character substring and tests equality. If both variables do not match, the path is assumed to be too long and printed.



@echo off
setlocal enabledelayedexpansion
for /F "tokens=1 delims=" %%i in ('dir /o:-n /b /s') do (
set filename=%%i
set part=!filename:~0,260!
if !filename! NEQ !part! echo !filename!
)





share|improve this answer





























    0














    If I´ve understand, you may needed a efficient counter to strings?
    so, see :_cnt_str_len above, but I´m definitely don´t get understood then part: IF !Test! NEQ . (



    @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 :_cnt_str_len
    echo/!Test! have len = !_cnt_str_len!**strong text**
    Set StrLen=!_cnt_str_len!
    rem :: call set Test=%%Test:~%Limit%%%.
    IF "!_cnt_str_len!" GEQ "!Limit!" (
    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

    goto :_end_of_file

    :_cnt_str_len

    if defined _cnt_str_len set _cnt_str_len=

    for /f %%h in ('cmd /u /c set /p "=%Test:"= %"^<nul^|find /v /c ""') do (

    set _cnt_str_len=%%~h&& call set _cnt_str_len=!_cnt_str_len!

    exit /b

    )

    :_end_of_file





    share|improve this answer































      0














      You could filter the DIR output by a program using regex.

      findstr could do that, but unfortunetly the regex is very limited and it supports
      only search patterns up to 254 characters.

      The code could be:



      @echo off
      setlocal enabledelayedexpansion
      set "_LIMIT_=%~1"

      set _PATTERN_=
      for /l %%n in (1,1,%_LIMIT_%) do (set "_PATTERN_=!_PATTERN_!.")

      dir /o:-n /b /s | findstr /r "/c:%_PATTERN_%"


      If you don't mind using third party programs you could use grep instead.
      This is very easy:



      @echo off
      setlocal
      set "_LIMIT_=%~1"

      dir /o:-n /b /s | grep -E .{%_LIMIT_%}





      share|improve this answer





















        Your Answer








        StackExchange.ready(function() {
        var channelOptions = {
        tags: "".split(" "),
        id: "3"
        };
        initTagRenderer("".split(" "), "".split(" "), channelOptions);

        StackExchange.using("externalEditor", function() {
        // Have to fire editor after snippets, if snippets enabled
        if (StackExchange.settings.snippets.snippetsEnabled) {
        StackExchange.using("snippets", function() {
        createEditor();
        });
        }
        else {
        createEditor();
        }
        });

        function createEditor() {
        StackExchange.prepareEditor({
        heartbeatType: 'answer',
        autoActivateHeartbeat: false,
        convertImagesToLinks: true,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: 10,
        bindNavPrevention: true,
        postfix: "",
        imageUploader: {
        brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
        contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
        allowUrls: true
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f677503%2ffast-nt-batch-script-for-determining-path-lengths-in-a-folder%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        4 Answers
        4






        active

        oldest

        votes








        4 Answers
        4






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        2














        To check the length of an environment variable, you can do something similar to this:



        set a=1234567890123

        if [%a:~0,-12%]== (
        echo a is shorter than 13
        ) else (
        echo %a% is longer than 12
        )


        Expression %a:~0,-12% returns all but the last 12 characters of variable a.



        Enter set /? to get details.



        However, I am not sure if this also work under NT. I have tested it as CMD script under Windows 7.






        share|improve this answer





















        • Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
          – dbenham
          Nov 18 '13 at 16:45










        • Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
          – Axel Kemper
          Nov 19 '13 at 18:42
















        2














        To check the length of an environment variable, you can do something similar to this:



        set a=1234567890123

        if [%a:~0,-12%]== (
        echo a is shorter than 13
        ) else (
        echo %a% is longer than 12
        )


        Expression %a:~0,-12% returns all but the last 12 characters of variable a.



        Enter set /? to get details.



        However, I am not sure if this also work under NT. I have tested it as CMD script under Windows 7.






        share|improve this answer





















        • Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
          – dbenham
          Nov 18 '13 at 16:45










        • Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
          – Axel Kemper
          Nov 19 '13 at 18:42














        2












        2








        2






        To check the length of an environment variable, you can do something similar to this:



        set a=1234567890123

        if [%a:~0,-12%]== (
        echo a is shorter than 13
        ) else (
        echo %a% is longer than 12
        )


        Expression %a:~0,-12% returns all but the last 12 characters of variable a.



        Enter set /? to get details.



        However, I am not sure if this also work under NT. I have tested it as CMD script under Windows 7.






        share|improve this answer












        To check the length of an environment variable, you can do something similar to this:



        set a=1234567890123

        if [%a:~0,-12%]== (
        echo a is shorter than 13
        ) else (
        echo %a% is longer than 12
        )


        Expression %a:~0,-12% returns all but the last 12 characters of variable a.



        Enter set /? to get details.



        However, I am not sure if this also work under NT. I have tested it as CMD script under Windows 7.







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 18 '13 at 15:52









        Axel Kemper

        2,63711521




        2,63711521












        • Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
          – dbenham
          Nov 18 '13 at 16:45










        • Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
          – Axel Kemper
          Nov 19 '13 at 18:42


















        • Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
          – dbenham
          Nov 18 '13 at 16:45










        • Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
          – Axel Kemper
          Nov 19 '13 at 18:42
















        Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
        – dbenham
        Nov 18 '13 at 16:45




        Right idea, but you have got your logic mixed up. You want "%a:~13%"=="" to test if value is shorter than 13 chars. You also want quotes to protect against poison chars. Like you, I do not know if NT supports substring operation.
        – dbenham
        Nov 18 '13 at 16:45












        Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
        – Axel Kemper
        Nov 19 '13 at 18:42




        Your sample expression is also true for a with 13 characters, ie not shorter than 13. Am I missing something?
        – Axel Kemper
        Nov 19 '13 at 18:42













        0














        There is no built-in command for determining the length of a string in a batch file. It necessarily involves ugly hacks like writing to a file. However, it is relatively easy to check whether a string exceeds a fixed length such as the 260 character limit. The following script grabs a 260 character substring and tests equality. If both variables do not match, the path is assumed to be too long and printed.



        @echo off
        setlocal enabledelayedexpansion
        for /F "tokens=1 delims=" %%i in ('dir /o:-n /b /s') do (
        set filename=%%i
        set part=!filename:~0,260!
        if !filename! NEQ !part! echo !filename!
        )





        share|improve this answer


























          0














          There is no built-in command for determining the length of a string in a batch file. It necessarily involves ugly hacks like writing to a file. However, it is relatively easy to check whether a string exceeds a fixed length such as the 260 character limit. The following script grabs a 260 character substring and tests equality. If both variables do not match, the path is assumed to be too long and printed.



          @echo off
          setlocal enabledelayedexpansion
          for /F "tokens=1 delims=" %%i in ('dir /o:-n /b /s') do (
          set filename=%%i
          set part=!filename:~0,260!
          if !filename! NEQ !part! echo !filename!
          )





          share|improve this answer
























            0












            0








            0






            There is no built-in command for determining the length of a string in a batch file. It necessarily involves ugly hacks like writing to a file. However, it is relatively easy to check whether a string exceeds a fixed length such as the 260 character limit. The following script grabs a 260 character substring and tests equality. If both variables do not match, the path is assumed to be too long and printed.



            @echo off
            setlocal enabledelayedexpansion
            for /F "tokens=1 delims=" %%i in ('dir /o:-n /b /s') do (
            set filename=%%i
            set part=!filename:~0,260!
            if !filename! NEQ !part! echo !filename!
            )





            share|improve this answer












            There is no built-in command for determining the length of a string in a batch file. It necessarily involves ugly hacks like writing to a file. However, it is relatively easy to check whether a string exceeds a fixed length such as the 260 character limit. The following script grabs a 260 character substring and tests equality. If both variables do not match, the path is assumed to be too long and printed.



            @echo off
            setlocal enabledelayedexpansion
            for /F "tokens=1 delims=" %%i in ('dir /o:-n /b /s') do (
            set filename=%%i
            set part=!filename:~0,260!
            if !filename! NEQ !part! echo !filename!
            )






            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 18 '13 at 16:09









            Marcks Thomas

            5,51311736




            5,51311736























                0














                If I´ve understand, you may needed a efficient counter to strings?
                so, see :_cnt_str_len above, but I´m definitely don´t get understood then part: IF !Test! NEQ . (



                @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 :_cnt_str_len
                echo/!Test! have len = !_cnt_str_len!**strong text**
                Set StrLen=!_cnt_str_len!
                rem :: call set Test=%%Test:~%Limit%%%.
                IF "!_cnt_str_len!" GEQ "!Limit!" (
                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

                goto :_end_of_file

                :_cnt_str_len

                if defined _cnt_str_len set _cnt_str_len=

                for /f %%h in ('cmd /u /c set /p "=%Test:"= %"^<nul^|find /v /c ""') do (

                set _cnt_str_len=%%~h&& call set _cnt_str_len=!_cnt_str_len!

                exit /b

                )

                :_end_of_file





                share|improve this answer




























                  0














                  If I´ve understand, you may needed a efficient counter to strings?
                  so, see :_cnt_str_len above, but I´m definitely don´t get understood then part: IF !Test! NEQ . (



                  @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 :_cnt_str_len
                  echo/!Test! have len = !_cnt_str_len!**strong text**
                  Set StrLen=!_cnt_str_len!
                  rem :: call set Test=%%Test:~%Limit%%%.
                  IF "!_cnt_str_len!" GEQ "!Limit!" (
                  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

                  goto :_end_of_file

                  :_cnt_str_len

                  if defined _cnt_str_len set _cnt_str_len=

                  for /f %%h in ('cmd /u /c set /p "=%Test:"= %"^<nul^|find /v /c ""') do (

                  set _cnt_str_len=%%~h&& call set _cnt_str_len=!_cnt_str_len!

                  exit /b

                  )

                  :_end_of_file





                  share|improve this answer


























                    0












                    0








                    0






                    If I´ve understand, you may needed a efficient counter to strings?
                    so, see :_cnt_str_len above, but I´m definitely don´t get understood then part: IF !Test! NEQ . (



                    @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 :_cnt_str_len
                    echo/!Test! have len = !_cnt_str_len!**strong text**
                    Set StrLen=!_cnt_str_len!
                    rem :: call set Test=%%Test:~%Limit%%%.
                    IF "!_cnt_str_len!" GEQ "!Limit!" (
                    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

                    goto :_end_of_file

                    :_cnt_str_len

                    if defined _cnt_str_len set _cnt_str_len=

                    for /f %%h in ('cmd /u /c set /p "=%Test:"= %"^<nul^|find /v /c ""') do (

                    set _cnt_str_len=%%~h&& call set _cnt_str_len=!_cnt_str_len!

                    exit /b

                    )

                    :_end_of_file





                    share|improve this answer














                    If I´ve understand, you may needed a efficient counter to strings?
                    so, see :_cnt_str_len above, but I´m definitely don´t get understood then part: IF !Test! NEQ . (



                    @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 :_cnt_str_len
                    echo/!Test! have len = !_cnt_str_len!**strong text**
                    Set StrLen=!_cnt_str_len!
                    rem :: call set Test=%%Test:~%Limit%%%.
                    IF "!_cnt_str_len!" GEQ "!Limit!" (
                    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

                    goto :_end_of_file

                    :_cnt_str_len

                    if defined _cnt_str_len set _cnt_str_len=

                    for /f %%h in ('cmd /u /c set /p "=%Test:"= %"^<nul^|find /v /c ""') do (

                    set _cnt_str_len=%%~h&& call set _cnt_str_len=!_cnt_str_len!

                    exit /b

                    )

                    :_end_of_file






                    share|improve this answer














                    share|improve this answer



                    share|improve this answer








                    edited Dec 13 '18 at 19:28

























                    answered Dec 13 '18 at 19:12









                    kaputtz

                    14




                    14























                        0














                        You could filter the DIR output by a program using regex.

                        findstr could do that, but unfortunetly the regex is very limited and it supports
                        only search patterns up to 254 characters.

                        The code could be:



                        @echo off
                        setlocal enabledelayedexpansion
                        set "_LIMIT_=%~1"

                        set _PATTERN_=
                        for /l %%n in (1,1,%_LIMIT_%) do (set "_PATTERN_=!_PATTERN_!.")

                        dir /o:-n /b /s | findstr /r "/c:%_PATTERN_%"


                        If you don't mind using third party programs you could use grep instead.
                        This is very easy:



                        @echo off
                        setlocal
                        set "_LIMIT_=%~1"

                        dir /o:-n /b /s | grep -E .{%_LIMIT_%}





                        share|improve this answer


























                          0














                          You could filter the DIR output by a program using regex.

                          findstr could do that, but unfortunetly the regex is very limited and it supports
                          only search patterns up to 254 characters.

                          The code could be:



                          @echo off
                          setlocal enabledelayedexpansion
                          set "_LIMIT_=%~1"

                          set _PATTERN_=
                          for /l %%n in (1,1,%_LIMIT_%) do (set "_PATTERN_=!_PATTERN_!.")

                          dir /o:-n /b /s | findstr /r "/c:%_PATTERN_%"


                          If you don't mind using third party programs you could use grep instead.
                          This is very easy:



                          @echo off
                          setlocal
                          set "_LIMIT_=%~1"

                          dir /o:-n /b /s | grep -E .{%_LIMIT_%}





                          share|improve this answer
























                            0












                            0








                            0






                            You could filter the DIR output by a program using regex.

                            findstr could do that, but unfortunetly the regex is very limited and it supports
                            only search patterns up to 254 characters.

                            The code could be:



                            @echo off
                            setlocal enabledelayedexpansion
                            set "_LIMIT_=%~1"

                            set _PATTERN_=
                            for /l %%n in (1,1,%_LIMIT_%) do (set "_PATTERN_=!_PATTERN_!.")

                            dir /o:-n /b /s | findstr /r "/c:%_PATTERN_%"


                            If you don't mind using third party programs you could use grep instead.
                            This is very easy:



                            @echo off
                            setlocal
                            set "_LIMIT_=%~1"

                            dir /o:-n /b /s | grep -E .{%_LIMIT_%}





                            share|improve this answer












                            You could filter the DIR output by a program using regex.

                            findstr could do that, but unfortunetly the regex is very limited and it supports
                            only search patterns up to 254 characters.

                            The code could be:



                            @echo off
                            setlocal enabledelayedexpansion
                            set "_LIMIT_=%~1"

                            set _PATTERN_=
                            for /l %%n in (1,1,%_LIMIT_%) do (set "_PATTERN_=!_PATTERN_!.")

                            dir /o:-n /b /s | findstr /r "/c:%_PATTERN_%"


                            If you don't mind using third party programs you could use grep instead.
                            This is very easy:



                            @echo off
                            setlocal
                            set "_LIMIT_=%~1"

                            dir /o:-n /b /s | grep -E .{%_LIMIT_%}






                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Dec 14 '18 at 9:00









                            Konrad

                            211




                            211






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Super User!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.





                                Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                                Please pay close attention to the following guidance:


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fsuperuser.com%2fquestions%2f677503%2ffast-nt-batch-script-for-determining-path-lengths-in-a-folder%23new-answer', 'question_page');
                                }
                                );

                                Post as a guest















                                Required, but never shown





















































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown

































                                Required, but never shown














                                Required, but never shown












                                Required, but never shown







                                Required, but never shown







                                Popular posts from this blog

                                "Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

                                Alcedinidae

                                Origin of the phrase “under your belt”?