home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2 / PcPro-2a.iso / Ivr / VisProg.exe / TreeDir.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-10-05  |  3.3 KB  |  94 lines

  1. VERSION 5.00
  2. Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "MSCOMCTL.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   5010
  6.    ClientLeft      =   60
  7.    ClientTop       =   345
  8.    ClientWidth     =   7050
  9.    LinkTopic       =   "Form1"
  10.    ScaleHeight     =   5010
  11.    ScaleWidth      =   7050
  12.    StartUpPosition =   3  'Windows Default
  13.    Begin MSComctlLib.TreeView tvwControl 
  14.       Height          =   4335
  15.       Left            =   120
  16.       TabIndex        =   1
  17.       Top             =   480
  18.       Width           =   4815
  19.       _ExtentX        =   8493
  20.       _ExtentY        =   7646
  21.       _Version        =   393217
  22.       Sorted          =   -1  'True
  23.       Style           =   7
  24.       SingleSel       =   -1  'True
  25.       Appearance      =   1
  26.    End
  27.    Begin VB.CommandButton cmdEnd 
  28.       Caption         =   "End"
  29.       Height          =   375
  30.       Left            =   5760
  31.       TabIndex        =   0
  32.       Top             =   4560
  33.       Width           =   1215
  34.    End
  35.    Begin VB.Label lblMessage 
  36.       AutoSize        =   -1  'True
  37.       Caption         =   "Label1"
  38.       Height          =   195
  39.       Left            =   120
  40.       TabIndex        =   2
  41.       Top             =   240
  42.       Width           =   480
  43.    End
  44. Attribute VB_Name = "Form1"
  45. Attribute VB_GlobalNameSpace = False
  46. Attribute VB_Creatable = False
  47. Attribute VB_PredeclaredId = True
  48. Attribute VB_Exposed = False
  49. Option Explicit
  50. Dim FileSystem As Scripting.FileSystemObject    ' FSO File system object
  51. Dim Drives As Scripting.Drives                  ' FSO Drives collection
  52. Private Sub Form_Load()
  53.     Dim nodX As Node
  54.     Dim Drive As Scripting.Drive
  55.         
  56.     ' Centre form on screen
  57.     Move (Screen.Width - Width) / 2, (Screen.Height - Height) / 2
  58.     ' Initialise the file system variables
  59.     Set FileSystem = CreateObject("Scripting.FileSystemObject")
  60.     Set Drives = FileSystem.Drives
  61.             
  62.     For Each Drive In Drives
  63.         Set nodX = tvwControl.Nodes.Add(, tvwChild, Drive.DriveLetter & ":\", Drive.DriveLetter & ":")
  64.     Next
  65.     lblMessage = "Click on any drive letter to load its folders."
  66. End Sub
  67. Private Sub cmdEnd_Click()
  68.   Unload Me
  69.   Set Form1 = Nothing
  70.   End
  71. End Sub
  72. Private Sub tvwControl_Click()
  73.     Dim nodX As Node
  74.     ' Show a wait message for long searches
  75.     lblMessage = "Searching drive " & tvwControl.SelectedItem & " for folders ... please wait"
  76.     ' Identify the selected node
  77.     Set nodX = tvwControl.SelectedItem
  78.     ' If it's a drive letter with no sub-tree, then scan it
  79.     If (Right$(nodX.Text, 1) = ":") And (nodX.Children = 0) Then GetAllDrivesFolders nodX, nodX.Text & "\"
  80.     nodX.Expanded = True
  81.     lblMessage = "Total folders displayed : " & tvwControl.Nodes.Count - Drives.Count
  82. End Sub
  83. Public Sub GetAllDrivesFolders(ParentNode As Node, FileSpec As String)
  84.     Dim nodX As Node
  85.     Dim Folder As Scripting.Folder
  86.     Dim SubFolders As Scripting.Folders
  87.     Set SubFolders = FileSystem.GetFolder(FileSpec).SubFolders
  88.     For Each Folder In SubFolders
  89.         Set nodX = tvwControl.Nodes.Add(ParentNode.Key, tvwChild, FileSpec & Folder.Name, Folder.Name)
  90.         GetAllDrivesFolders nodX, FileSpec & Folder.Name & "\"
  91.     Next
  92.     ParentNode.Sorted = True
  93. End Sub
  94.