home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / tree / tree.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1995-09-06  |  5.8 KB  |  187 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    Caption         =   "Directory - Sizes"
  4.    ClientHeight    =   6600
  5.    ClientLeft      =   1725
  6.    ClientTop       =   1695
  7.    ClientWidth     =   7275
  8.    Height          =   7005
  9.    Icon            =   TREE.FRX:0000
  10.    Left            =   1665
  11.    LinkTopic       =   "Form1"
  12.    ScaleHeight     =   6600
  13.    ScaleWidth      =   7275
  14.    Top             =   1350
  15.    Width           =   7395
  16.    Begin CommandButton Command1 
  17.       Caption         =   "Scan"
  18.       Height          =   315
  19.       Left            =   120
  20.       TabIndex        =   3
  21.       Top             =   180
  22.       Width           =   795
  23.    End
  24.    Begin Outline DirOutline 
  25.       FontBold        =   0   'False
  26.       FontItalic      =   0   'False
  27.       FontName        =   "Fixedsys"
  28.       FontSize        =   9
  29.       FontStrikethru  =   0   'False
  30.       FontUnderline   =   0   'False
  31.       Height          =   5955
  32.       Left            =   120
  33.       PictureClosed   =   TREE.FRX:0302
  34.       PictureLeaf     =   TREE.FRX:045C
  35.       PictureMinus    =   TREE.FRX:05B6
  36.       PictureOpen     =   TREE.FRX:0710
  37.       PicturePlus     =   TREE.FRX:086A
  38.       TabIndex        =   2
  39.       Top             =   540
  40.       Width           =   7035
  41.    End
  42.    Begin DriveListBox Drive1 
  43.       Height          =   315
  44.       Left            =   1620
  45.       TabIndex        =   1
  46.       Top             =   180
  47.       Width           =   5535
  48.    End
  49.    Begin Label Label1 
  50.       Caption         =   "Drive"
  51.       Height          =   255
  52.       Left            =   1080
  53.       TabIndex        =   0
  54.       Top             =   240
  55.       Width           =   495
  56.    End
  57. Dim Anzahl As Integer
  58. Dim Terminate As Integer
  59. Function AddAllInNextLevel (CurrentPath As String, Level As Integer) As Long
  60.     Dim Count, D(), i, DirName  ' Declare variables.
  61.     Dim ATTR_Directory
  62.     Dim Total, GrandTotal, SubTotal As Long
  63.     Dim AnzahlNow As Integer
  64.     Dim Ausgabe As String
  65.     Counter = 0
  66.     Count = 0
  67.     Total = 0
  68.     GrandTotal = 0
  69.     SubTotal = 0
  70.     ATTR_Directory = 16
  71.     ATTR_Normal = 0
  72.     DirName = Dir(CurrentPath + "*.*", ATTR_Directory)' Get first directory name.
  73.     'Iterate through PATH, caching all subdirectories in D()
  74.     Do While DirName <> ""
  75.     If DirName <> "." And DirName <> ".." Then
  76.         If (GetAttr(CurrentPath + DirName) And ATTR_Directory) <> 0 Then
  77.         If (Count Mod 10) = 0 Then
  78.             ReDim Preserve D(Count + 10)    ' Resize the array.
  79.         End If
  80.         Count = Count + 1   ' Increment counter.
  81.         D(Count) = DirName
  82.         End If
  83.     End If
  84.     DirName = Dir   ' Get another directory name.
  85.     Loop
  86.     ' -> Gr
  87. e des aktuellen Verzeichnis bestimmen
  88.     DirName = Dir(CurrentPath + "*.*", 0)' Get first directory name.
  89.     On Error GoTo ErrorHandler
  90.     Do While DirName <> ""
  91.      If (GetAttr(CurrentPath + DirName) And ATTR_Directory) = 0 Then
  92.            Total = Total + FileLen(CurrentPath + DirName)
  93.            Counter = Counter + 1
  94.            If Counter Mod 50 = 0 Then
  95.            Form1.Caption = "Scan: " + CurrentPath & "\ (" + Format(Total / 1024, "#######0") + ")"
  96.            End If
  97.        End If
  98.        DirName = Dir   ' Get another name.
  99.     Loop
  100.     ' Now recursively iterate through each cached subdirectory.
  101.     For i = 1 To Count
  102.        
  103.        DirOutline.AddItem D(i) ' Put name in list box.
  104.        Anzahl = Anzahl + 1
  105.        AnzahlNow = Anzahl
  106.        DirOutline.Expand(Anzahl) = True
  107.        DirOutline.Indent(Anzahl) = Level
  108.        Form1.Caption = "Scan: " + CurrentPath & D(i) & "\ (" + Format(GrandTotal / 1024, "#######0") + ")"
  109.     DoEvents
  110.     If Terminate Then
  111.        Exit Function
  112.     End If
  113.        SubTotal = AddAllInNextLevel(CurrentPath & D(i) & "\", Level + 1)
  114.        GrandTotal = GrandTotal + SubTotal
  115.        
  116.        Ausgabe = Format(SubTotal / (1024), "######0 kB ")
  117.        Ausgabe = String$(12 - Len(Ausgabe), " ") & Ausgabe
  118.        DirOutline.List(AnzahlNow) = Ausgabe + D(i)' Put name in list box.
  119.     Next i
  120.     AddAllInNextLevel = GrandTotal + Total
  121.     Exit Function
  122. ErrorHandler:
  123.     Message = "File : " + CurrentPath + DirName + " - Error : " + Error$
  124.     Erg = MsgBox(Message, 48, "FileLen-Error")
  125.     Resume Next
  126. End Function
  127. Sub Command1_Click ()
  128. ' hier wird alle Arbeit getan :
  129. ' Anfange mit dem Root-Directory:
  130.     If Terminate = False Then
  131.     Terminate = True
  132.     Exit Sub
  133.     End If
  134.     Dim Path As String
  135.     Dim Ausgabe As String
  136.     Dim Total As Long
  137.     Dim Count, D(), i, DirName  ' Declare variables.
  138.     DirOutline.Clear
  139.     Path = Left(Drive1.Drive, 2) + "\"
  140.     Anzahl = 0
  141.     Terminate = False
  142.     Form1.Caption = "Scan: " + Path
  143.     Command1.Caption = "STOP"
  144.     Refresh
  145.     DirOutline.AddItem Path, 0   ' Put name in list box.
  146.     DirOutline.Expand(0) = True
  147.     Total = AddAllInNextLevel(Path, 1)
  148.     If Terminate = True Then
  149.      DirOutline.Clear
  150.     End If
  151.        
  152.     Ausgabe = Format(Total / (1024), "######0 kB ")
  153.     Ausgabe = String$(12 - Len(Ausgabe), " ") & Ausgabe
  154.     DirOutline.List(0) = Ausgabe + Path' Put name in list box.
  155.     Terminate = True
  156.     Command1.Caption = "SCAN"
  157.     Form1.Caption = "Directory - Sizes"
  158. End Sub
  159. Sub DirOutline_Click ()
  160.     If DirOutline.Expand(DirOutline.ListIndex) Then
  161.        DirOutline.Expand(DirOutline.ListIndex) = False
  162.     Else
  163.        DirOutline.Expand(DirOutline.ListIndex) = True
  164.     End If
  165. End Sub
  166. Sub Form_Load ()
  167.     Terminate = True
  168. End Sub
  169. Sub Form_Resize ()
  170.     If Form1.WindowState = 1 Then
  171.     Exit Sub
  172.     End If
  173.     If Height < 4000 Then
  174.     Height = 4000
  175.     End If
  176.     If Width < 6000 Then
  177.     Width = 6000
  178.     End If
  179.     DirOutline.Height = Height - 1000
  180.     DirOutline.Width = Width - 400
  181.     Drive1.Width = Width - 1900
  182.     Refresh
  183. End Sub
  184. Sub Form_Unload (Cancel As Integer)
  185.     End
  186. End Sub
  187.