[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Determine the path length of a volume or folder

Posted on 2007-07-26
3
Medium Priority
?
443 Views
Last Modified: 2010-03-05
Experts,

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

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

Any suggestions.

ITBenelux
0
Comment
Question by:ITBenelux
3 Comments
 
LVL 31

Expert Comment

by:merowinger
ID: 19572819
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
 Next
End Sub

0
 
LVL 5

Accepted Solution

by:
ardrac earned 1000 total points
ID: 19573112
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;

d:\personal\Photos\DSCN0001.JPG,31
d:\personal\Photos\DSCN0042.JPG,31
d:\personal\Photos\harry.jpg,28

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.
;
; EXAMPLE USAGE
;--------------------------------------------

$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.")
    Exit
EndIf

$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)
    Next
EndIf

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)
      
      
      Else
         While StringInStr($szMask,"\")
              $szRoot = $szRoot & StringLeft($szMask,StringInStr($szMask,"\"))
              $szMask = StringTrimLeft($szMask,StringInStr($szMask,"\"))
         Wend
    EndIf
    If $nOption = 0 Then
         _FileSearchUtil($szRoot, $szMask, $szReturn)
    Else
         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)
                   Wend
                   FileClose($hFile)
              EndIf
              _FileSearchUtil($szRoot, $szMask, $szReturn)
              If $szPathList == "*" Then ExitLoop
              $szPathList = StringTrimLeft($szPathList,1)
              $szRoot = StringLeft($szPathList,StringInStr($szPathList,"*")-1) & "\"
              $szPathList = StringTrimLeft($szPathList,StringInStr($szPathList,"*")-1)
         Wend
    EndIf
    If $szReturn = "" Then
         $aNULL[0] = 0
         Return $aNULL
    Else
         Return StringSplit(StringTrimRight($szReturn,1),"*")
    EndIf
EndFunc

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)
         Wend
         FileClose($hFile)
    EndIf
EndFunc

******************************

Hope it helps
0
 
LVL 1

Author Comment

by:ITBenelux
ID: 19585552
The script works Thx
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On July 14th 2015, Windows Server 2003 will become End of Support, leaving hundreds of thousands of servers around the world that still run this 12 year old operating system vulnerable and potentially out of compliance in many organisations around t…
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…
Suggested Courses

830 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