home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / getrea1a / form1.frm (.txt) next >
Encoding:
Visual Basic Form  |  1999-07-07  |  5.4 KB  |  184 lines

  1. VERSION 5.00
  2. Begin VB.Form Form1 
  3.    BorderStyle     =   1  'Fixed Single
  4.    Caption         =   "Size Check"
  5.    ClientHeight    =   5088
  6.    ClientLeft      =   36
  7.    ClientTop       =   324
  8.    ClientWidth     =   4188
  9.    LinkTopic       =   "Form1"
  10.    MaxButton       =   0   'False
  11.    ScaleHeight     =   5088
  12.    ScaleWidth      =   4188
  13.    StartUpPosition =   3  'Windows Default
  14.    Begin VB.ComboBox cboFileSistem 
  15.       Height          =   288
  16.       ItemData        =   "Form1.frx":0000
  17.       Left            =   120
  18.       List            =   "Form1.frx":000A
  19.       Style           =   2  'Dropdown List
  20.       TabIndex        =   6
  21.       Top             =   3480
  22.       Width           =   3972
  23.    End
  24.    Begin VB.Frame Frame1 
  25.       Height          =   3252
  26.       Left            =   120
  27.       TabIndex        =   0
  28.       Top             =   120
  29.       Width           =   3972
  30.       Begin VB.CommandButton cmdCheckFile 
  31.          Caption         =   "Check File Size"
  32.          Height          =   372
  33.          Left            =   1920
  34.          TabIndex        =   5
  35.          Top             =   2760
  36.          Width           =   1932
  37.       End
  38.       Begin VB.CommandButton cmdCheckFolder 
  39.          Caption         =   "Check Folder Size"
  40.          Height          =   372
  41.          Left            =   1920
  42.          TabIndex        =   4
  43.          Top             =   2280
  44.          Width           =   1932
  45.       End
  46.       Begin VB.DirListBox Dir1 
  47.          Height          =   2232
  48.          Left            =   120
  49.          TabIndex        =   3
  50.          Top             =   240
  51.          Width           =   1572
  52.       End
  53.       Begin VB.DriveListBox Drive1 
  54.          Height          =   288
  55.          Left            =   120
  56.          TabIndex        =   2
  57.          Top             =   2640
  58.          Width           =   1572
  59.       End
  60.       Begin VB.FileListBox File1 
  61.          Height          =   1800
  62.          Left            =   1920
  63.          TabIndex        =   1
  64.          Top             =   240
  65.          Width           =   1932
  66.       End
  67.    End
  68.    Begin VB.Label lblResult 
  69.       Alignment       =   2  'Center
  70.       Height          =   972
  71.       Left            =   120
  72.       TabIndex        =   7
  73.       Top             =   3960
  74.       Width           =   3972
  75.    End
  76. Attribute VB_Name = "Form1"
  77. Attribute VB_GlobalNameSpace = False
  78. Attribute VB_Creatable = False
  79. Attribute VB_PredeclaredId = True
  80. Attribute VB_Exposed = False
  81. Option Explicit
  82. Dim ClasterSize As Integer
  83. Dim fs As New FileSystemObject
  84. Dim FolderSize
  85. Dim ActFolderSize
  86. Private Sub cboFileSistem_Click()
  87. Select Case cboFileSistem
  88.    Case "FAT16"
  89.     ClasterSize = 16
  90.    Case "FAT32"
  91.     ClasterSize = 4
  92. End Select
  93. End Sub
  94. Private Sub cmdCheckFile_Click()
  95. Dim FilePath As String
  96. Dim S As Double
  97. Dim ActSize As Double
  98. If Right(Dir1.Path, 1) <> "\" Then
  99.    FilePath = Dir1.Path & "\" & File1.FileName
  100.   Else
  101.    FilePath = Dir1.Path & File1.FileName
  102. End If
  103. S = GetFileSize(FilePath)
  104. If S <> 0 Then S = S / 1024
  105. ActSize = GetActualFileSize(FilePath)
  106. Call ShowResult(FilePath, S, ActSize, " Kb ")
  107. End Sub
  108. Private Sub cmdCheckFolder_Click()
  109. Screen.MousePointer = 11
  110. Form1.Enabled = False
  111. DoFolder Dir1.Path
  112. Call ShowResult(Dir1.Path, FolderSize / 1024, ActFolderSize, " Mb ")
  113. FolderSize = 0
  114. ActFolderSize = 0
  115. Form1.Enabled = True
  116. Screen.MousePointer = 1
  117. End Sub
  118. Private Sub Drive1_Change()
  119.    Dir1.Path = Drive1.Drive   ' When drive changes, set directory path.
  120. End Sub
  121. Private Sub Dir1_Change()
  122.    File1.Path = Dir1.Path   ' When directory changes, set file path.
  123. End Sub
  124. Private Sub File1_DblClick()
  125. cmdCheckFile_Click
  126. End Sub
  127. Private Sub Form_Load()
  128. cboFileSistem.ListIndex = 0
  129. End Sub
  130. ' This function returns lenght of file in bytes
  131. Public Function GetFileSize(Path As String) As Long
  132. On Error Resume Next
  133. GetFileSize = FileLen(Path)
  134. On Error GoTo 0
  135. End Function
  136. 'This function returns the space that file  file is cathing on drive in Kb
  137. Public Function GetActualFileSize(FilePath As String) As Long
  138. Dim Size
  139. On Error Resume Next
  140. Size = GetFileSize(FilePath)
  141. 'If size=0 exit function
  142. If Size = 0 Then
  143.    GetActualFileSize = 0
  144.    Exit Function
  145. End If
  146. Size = Size / 1024 'Get size in Kb
  147. If Size < ClasterSize Then
  148.    GetActualFileSize = ClasterSize
  149.    Exit Function
  150. End If
  151. If Size / ClasterSize = Size \ ClasterSize Then
  152.    GetActualFileSize = Size
  153.   Else
  154.    GetActualFileSize = (Size \ ClasterSize + 1) * ClasterSize
  155. End If
  156. End Function
  157. Public Sub ShowResult(Name As String, Size As Double, ByVal ActualeSize As Double, Units As String)
  158. Dim Message As String
  159. Message = " File Name    : " & Name & vbCrLf & _
  160.           " Size         : " & Format(Size, "#0.00") & Units & vbCrLf & _
  161.           " Actuale Size : " & Format(ActualeSize, "#0.00") & Units
  162. lblResult.Caption = Message
  163. End Sub
  164. 'This function puts in FolderSize size of folder in Kb
  165. 'and in ActFolderSize : size on drive in Mb
  166. Public Sub DoFolder(Path As String)
  167. Dim fol As Folder
  168. Dim fi As Folder
  169. Dim fols As Folders
  170. Dim fils As Files
  171. Dim fil As File
  172. Set fol = fs.GetFolder(Path)
  173. Set fils = fol.Files
  174.  For Each fil In fils
  175.    FolderSize = FolderSize + GetFileSize(fil.Path) / 1024
  176.    ActFolderSize = ActFolderSize + GetActualFileSize(fil.Path) / 1024
  177.  Next fil
  178. Set fols = fol.SubFolders
  179. For Each fi In fols
  180. 'Recurcive call for next subfolder
  181.  DoFolder fi.Path
  182. Next fi
  183. End Sub
  184.