home *** CD-ROM | disk | FTP | other *** search
/ Programmer Plus 2007 / Programmer-Plus-2007.iso / Programming / Visual Basic new SourceCode and Projects / Directory Mapper / Directory.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1999-06-19  |  5.4 KB  |  192 lines

  1. VERSION 5.00
  2. Begin VB.Form frmDirectory 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Drive Mapper"
  5.    ClientHeight    =   2205
  6.    ClientLeft      =   45
  7.    ClientTop       =   330
  8.    ClientWidth     =   5280
  9.    Icon            =   "Directory.frx":0000
  10.    LinkTopic       =   "Form1"
  11.    MaxButton       =   0   'False
  12.    MinButton       =   0   'False
  13.    ScaleHeight     =   147
  14.    ScaleMode       =   3  'Pixel
  15.    ScaleWidth      =   352
  16.    StartUpPosition =   3  'Windows Default
  17.    Begin VB.Label lblFile 
  18.       Height          =   315
  19.       Left            =   150
  20.       TabIndex        =   3
  21.       Top             =   1650
  22.       Width           =   4965
  23.       WordWrap        =   -1  'True
  24.    End
  25.    Begin VB.Label lblFil 
  26.       AutoSize        =   -1  'True
  27.       Caption         =   "File:"
  28.       Height          =   195
  29.       Left            =   150
  30.       TabIndex        =   2
  31.       Top             =   1275
  32.       Width           =   285
  33.    End
  34.    Begin VB.Label lblDirectory 
  35.       Height          =   465
  36.       Left            =   150
  37.       TabIndex        =   1
  38.       Top             =   525
  39.       Width           =   4965
  40.       WordWrap        =   -1  'True
  41.    End
  42.    Begin VB.Label lblDir 
  43.       AutoSize        =   -1  'True
  44.       Caption         =   "Directory:"
  45.       Height          =   195
  46.       Left            =   150
  47.       TabIndex        =   0
  48.       Top             =   150
  49.       Width           =   675
  50.    End
  51. Attribute VB_Name = "frmDirectory"
  52. Attribute VB_GlobalNameSpace = False
  53. Attribute VB_Creatable = False
  54. Attribute VB_PredeclaredId = True
  55. Attribute VB_Exposed = False
  56. Option Explicit
  57. Const COLON = ":"
  58. Dim Drives As New Collection
  59. Dim Directory As New Collection
  60. Dim Files As New Collection
  61. Dim FileTree As New Collection
  62. Dim TreeLevel As Integer
  63. Dim FilePath As String
  64. Dim DriveLetter As String
  65. Dim PathName As String
  66. Dim DriveNum As Integer
  67. Dim FolderName As String
  68. Dim IsDrive As Boolean
  69. Dim CancelProg As Boolean
  70. Sub DeleteCollection(ByRef Col As Collection)
  71. Dim BlankCollection As New Collection
  72.     Set Col = BlankCollection
  73. End Sub
  74. Function GetDriveLetter(DriveIndex As Integer) As String
  75.     GetDriveLetter = Left(Right(Drives(DriveIndex), 3), 1)
  76. End Function
  77. Sub GetDrives()
  78. Dim i As Integer, MyDrive As String
  79.     On Error Resume Next
  80.     DeleteCollection Drives
  81.     For i = 0 To 25
  82.         MyDrive = Chr(i + 65) & COLON
  83.         If Dir(MyDrive, vbVolume) > "" Then
  84.             Drives.Add Dir(MyDrive, vbVolume) & " (" & MyDrive & ")"
  85.         End If
  86.     Next i
  87. End Sub
  88. Sub GetDirectory()
  89. Dim i As Integer, MyDir As String
  90.     DeleteCollection Directory
  91.     MyDir = Dir(PathName, vbDirectory)
  92.     Do While MyDir <> vbNullString
  93.         If MyDir <> "." And MyDir <> ".." Then
  94.             If (GetAttr(PathName & MyDir) And vbDirectory) = vbDirectory Then
  95.                 Directory.Add UCase(MyDir)
  96.                 DoEvents
  97.             End If
  98.         End If
  99.         MyDir = Dir()
  100.     Loop
  101. End Sub
  102. Sub GetFiles()
  103. Dim i As Integer, MyFile As String
  104.     DeleteCollection Files
  105.     MyFile = Dir(PathName, vbArchive + vbHidden + vbSystem + vbReadOnly)
  106.     Do While MyFile <> vbNullString
  107.         DoEvents
  108.         Files.Add UCase(MyFile)
  109.         MyFile = Dir()
  110.     Loop
  111. End Sub
  112. Sub GetPath()
  113. Dim i As Integer, s As String
  114.     DeleteCollection FileTree
  115.     Do
  116.         i = InStr(1, PathName, "\")
  117.         If i > 0 Then
  118.             s = Left(PathName, i - 1)
  119.             PathName = Right(PathName, Len(PathName) - i)
  120.             FileTree.Add s
  121.         End If
  122.     Loop Until i = 0
  123. End Sub
  124. Sub RefreshDir()
  125.     GetDrives
  126.     GetDirectory
  127.     GetFiles
  128. End Sub
  129. Private Sub Form_Load()
  130.     On Error Resume Next
  131.     FilePath = App.Path & "\DRIVES.MAP"
  132.     Kill FilePath
  133.     Open FilePath For Random As #1
  134.     Close
  135.     Open FilePath For Output As #1
  136.     RefreshDir
  137.     Show
  138.     StoreDrivesData
  139. End Sub
  140. Sub StoreDrivesData()
  141.     GetDrives
  142.     For DriveNum = 1 To Drives.Count
  143.         PathName = GetDriveLetter(DriveNum) & ":\"
  144.         IsDrive = True
  145.         If CancelProg Then Exit Sub
  146.         StoreDirData
  147.     Next DriveNum
  148.     End
  149. End Sub
  150. Sub StoreDirData()
  151. Dim FldVar As Integer, Path As String
  152. Dim OldDirectory As New Collection
  153.     On Error Resume Next
  154.     If CancelProg Then Exit Sub
  155.     TreeLevel = TreeLevel + 1
  156.     FolderName = "-> " & Dir(Left(PathName, Len(PathName) - 1), vbDirectory)
  157.     If IsDrive Then FolderName = "-> " & PathName
  158.     PrintToFile String((TreeLevel - 1) * 2, " ") & FolderName
  159.     lblDirectory = PathName
  160.     Path = PathName
  161.     lblFile = ""
  162.     GetDirectory
  163.     IsDrive = False
  164.     Set OldDirectory = Directory
  165.     StoreFilesData
  166.     For FldVar = 1 To OldDirectory.Count
  167.         PathName = Path & OldDirectory(FldVar) & "\"
  168.         StoreDirData
  169.         PathName = Path
  170.     Next FldVar
  171.     TreeLevel = TreeLevel - 1
  172. End Sub
  173. Sub StoreFilesData()
  174. Dim FilVar As Integer
  175.     GetFiles
  176.     For FilVar = 1 To Files.Count
  177.         DoEvents
  178.         PrintToFile String((TreeLevel - 1) * 2, " ") & Files(FilVar)
  179.         lblFile = Files(FilVar)
  180.     Next FilVar
  181. End Sub
  182. Sub PrintToFile(Text As String)
  183.     Debug.Print Text
  184.     Print #1, Text
  185. End Sub
  186. Private Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)
  187.     CancelProg = True
  188. End Sub
  189. Private Sub Form_Unload(Cancel As Integer)
  190.     Close
  191. End Sub
  192.