Determine the path length of a volume or folder

Posted on 2007-07-26
Last Modified: 2010-03-05

I want to know if there is a way or a tool who can provide me with the following info.  I need to know on my Windows 2003 Server the total length of the folders within a volume.
I suspect that there are folders who oversizes the max path length.  So an overview lik

 Folder x: 210 char.
 Folder y: 110 char.
 Folder z: 22 char.

Any suggestions.

Question by:ITBenelux
    LVL 31

    Expert Comment

    what about this?
    Set FSO = CreateObject("Scripting.FileSystemObject")
    ShowSubfolders FSO.GetFolder("C:\test")
    Sub ShowSubFolders(Folder)
     For Each Subfolder in Folder.SubFolders
     pathlen = len(Subfolder.Path)
     Wscript.Echo Subfolder.Path &" Lenght: " &pathlen
     ShowSubFolders Subfolder
    End Sub

    LVL 5

    Accepted Solution

    I had a similar issue I had to deal with a while ago. I tried using Vb script but when the path was over 255 characters it failed. Something to do with a strings maximum size being 255 characters in VB. The worst thing was I was running this to find out files with paths longer that 255 so it was a dead end.

    To get round this I modified a couple of autoIT scripts found on their forums. The end results is a script that you supply a top level folder to scan. It scans all files under the top level folder and subfolders and creates a output file whcih lists every file found and the total path length of each. I tested this with paths upto 500 characters long. It also runs very quick and allows you to filter by what ever file extension you want (use *.*) for all files.

    The output looks like;


    Is you are interested the code is below. Just put it into a file called Filelist.au3. Download AutoITv3 and run the script.


    ; _FileSearch( <Path and Mask>, <Option (0 - normal, 1- recursive)>)
    ; Returns array. Either Array of files (full path) where...
    ; Array[0] is number of files.
    ; Array[0] = 0 if nothing found.

    $results = InputBox("File List", "Specifiy full path to output file. Output file will be overwritten.", "d:\results.txt", "", _
        300, 150)
    $Type = InputBox("File List", "File Types to find", "*.*", "", _
        300, 150)

    $resultsfile = FileOpen($results, 2)

    If $resultsfile = -1 Then
        MsgBox(0, "Error", "Unable to open file.")

    $a = _FileSearch($Type,1)
    If $a[0] > 0 Then
        For $i = 1 to $a[0]
             $len = StringLen($a[$i])
                 FileWrite($resultsfile, $a[$i] & "," & $len & @CRLF)

    MsgBox(64, "File List", "File List Complete. Output saved to : " & $results)

    Func _FileSearch($szMask,$nOption)
        $szRoot = ""
        $hFile = 0
        $szBuffer = ""
        $szReturn = ""
        $szPathList = "*"
        Dim $aNULL[1]

          If Not StringInStr($szMask,"\") Then
            ;$szRoot = "d:\"
        $szRoot = InputBox("File List", "Specicify top level folder to scan. Can be UNC or mappped drive. Must have trailing backslash.", "d:\", "", _
        300, 150)
             While StringInStr($szMask,"\")
                  $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\"))
                  $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\"))
        If $nOption = 0 Then
             _FileSearchUtil($szRoot, $szMask, $szReturn)
             While 1
                  $hFile = FileFindFirstFile($szRoot & "*.*")
                  If $hFile >= 0 Then
                       $szBuffer = FileFindNextFile($hFile)
                       While Not @ERROR
                            If $szBuffer <> "." And $szBuffer <> ".." And _
                                 StringInStr(FileGetAttrib($szRoot & $szBuffer),"D") Then _
                                 $szPathList = $szPathList & $szRoot & $szBuffer & "*"
                            $szBuffer = FileFindNextFile($hFile)
                  _FileSearchUtil($szRoot, $szMask, $szReturn)
                  If $szPathList == "*" Then ExitLoop
                  $szPathList = StringTrimLeft($szPathList,1)
                  $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\"
                  $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1)
        If $szReturn = "" Then
             $aNULL[0] = 0
             Return $aNULL
             Return StringSplit(StringTrimRight($szReturn,1),"*")

    Func _FileSearchUtil(ByRef $ROOT, ByRef $MASK, ByRef $RETURN)
        $hFile = FileFindFirstFile($ROOT & $MASK)
        If $hFile >= 0 Then
             $szBuffer = FileFindNextFile($hFile)
             While Not @ERROR
                  If $szBuffer <> "." And $szBuffer <> ".." Then _
                       $RETURN = $RETURN & $ROOT & $szBuffer & "*"
                  $szBuffer = FileFindNextFile($hFile)


    Hope it helps
    LVL 1

    Author Comment

    The script works Thx

    Featured Post

    Highfive Gives IT Their Time Back

    Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

    Join & Write a Comment

    Some time ago I faced the need to use a uniform folder structure that spanned across numerous sites of an enterprise to be used as a common repository for the Software packages of the Configuration Manager 2007 infrastructure. Because the procedu…
    When you upgrade from Windows 8 to 8.1 or to Windows 10 or if you are like me you are on the Insider Program you may find yourself with many 450MB recovery partitions.  With a traditional disk that may not be a problem but with relatively smaller SS…
    Windows 8 comes with a dramatically different user interface known as Metro. Notably missing from the new interface is a Start button and Start Menu. Many users do not like it, much preferring the interface of earlier versions — Windows 7, Windows X…
    With the advent of Windows 10, Microsoft is pushing a Get Windows 10 icon into the notification area (system tray) of qualifying computers. There are many reasons for wanting to remove this icon. This two-part Experts Exchange video Micro Tutorial s…

    733 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    22 Experts available now in Live!

    Get 1:1 Help Now