|
-
Nov 12th, 1999, 06:56 AM
#1
Thread Starter
New Member
I am creating an app that will send me an email when a directory gets filled to a certain size. I have found many ways to get free space or file size, but nothing for total files an a specific directory. I could probably step through the directory getting all of the files and sized then add them, but thought there must be an easier way.
-
Nov 12th, 1999, 09:16 AM
#2
Junior Member
It's the same principle:
Private Sub cmdOK_Click()
Dim PathAndName As String
Dim FileSize As String
Dim Path As String
' If no file is selected, tell the user and exit this procedure.
If txtFileName.text = "" then
MsgBox "You must first select a file!"
Exit Sub
End if
' Make sure that Path ends with a \. (\)
If Right(filfiles.Path, 1) <> "\" Then
Path = filfiles.path + "\"
Else
Path = filfiles.Path
End if
'Extract the PAth and name of the selected file.
If txtFileName.Text = filfiles.Filename Then
PathAndName = Path + filfiles.FileName
Else
PathAndName = txtFileName.Text
End If
'The next statement may cause an error, so we set an error trap.
On error Foto FileLenError
'Get the file size of the file.
FileSize = Str(FileLen(PathAndName))
'Display the size of the file.
MsgBox "Size of "+PathAndName+": "FileSize+" bytes"
Exit Sub
FileLenError:
'There was an error, so display error message and exit.
MsgBox " Cannot find size of " + PathAndName
Exit sub
End Sub
Play around with this code...You should be able to change FileSize to DirSize or DirecotrySize. If not you'll have to run a loop finding all of the files then tell the file size of each and add them together.
-
Nov 12th, 1999, 11:52 AM
#3
Try using the FileSystemObject it means having to include the Scripting Runtime File(s).:
In a Form with a Textbox and CommandButton..
Code:
Private Sub Command1_Click()
Dim oFSO As Object
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set oFSO = oFSO.GetFolder(Text1)
Screen.MousePointer = vbHourglass
Caption = Format(oFSO.Size, "#,#") & " bytes."
Screen.MousePointer = vbDefault
Set oFSO = Nothing
End Sub
------------------
Aaron Young
Analyst Programmer
[email protected]
[email protected]
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|