How to Find the longest pathname on a server?

Posted on 2006-04-19
Last Modified: 2012-06-21
I have a fileserver running Windows 2003 server. I know there is a limit on the length of the path there can be. Files start getting hosed up and everything just gets ugly. Is there a way on a server or computer to determine the longest pathname for a group of folders without having to look manually?

pathname  example: //folder1/folder2/folder3/folder4/folder5/file.doc


Question by:tsi_admin
    LVL 33

    Expert Comment

    could use

    dir /ad /s

    to show you the directories...  

    Map a drive to the share...then run

    dir /ad /s

    LVL 33

    Expert Comment

    or go to the root:

    dir /ad /s  >>c:\temp\directories.txt

    Then open the directories.txt file using excel... you should be able to see the bigger directories here...

    use dir /s to see the files too if you want.


    Author Comment

    Thanks for the response, I tried the above, however it only gives the directory name, I need the number of characters of the entire path.


    LVL 76

    Accepted Solution

    We can do it with a script like the one below.  Follow these instructions to use it.

    1.  Copy the script and paste it into Notepad.
    2.  Save the file with a .vbs extension.
    3.  Go to a command prompt or click Start->Run and enter the following command:
        wscript scriptname.vbs C:\SomeStartingPath    (replace scriptname with the name of the script file)

    The script will display the longest path name and its length.

    Dim strRootFolder, strLongestPath, intLength, objFSO
    Set strRootFolder = WScript.Arguments(0)
    Set objFSO = CreateObject("Scripting.FileSystemObject")
    strLongestPath = ""
    intLength = 0
    ProcessFolder strRootFolder
    Set objFSO = Nothing
    WScript.Echo "The longest path name is: " & strLongestPath & vbCrLf & "Length = " & intLength

    Sub ProcessFolder(strPathname)
          Dim objFolder, objSubFolder, objFile
          Set objFolder = objFSO.GetFolder(strPathname)
          For Each objFile In objFolder.Files
                If Len(objFile.Path) > intLength Then
                      strLongestPath = objFile.Path
                      intLength = Len(strLongestPath)
                End If
          For Each objSubFolder In objFolder.SubFolders
                ProcessFolder objSubFolder.Path
          Set objFile = Nothing
          Set objSubFolder = Nothing
          Set objFolder = Nothing
    End Sub

    Featured Post

    IT, Stop Being Called Into Every Meeting

    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

    It is a known fact that servers reach the end of their lives. Some get there quicker than others, based on age, manufacturer, usage and several other factors. However, if your organization has spent time deploying Microsoft's Active Directory server…
    Learn about cloud computing and its benefits for small business owners.
    Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
    This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor ( If you're looking for how to monitor bandwidth using netflow or packet s…

    755 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

    17 Experts available now in Live!

    Get 1:1 Help Now