Solved

File Size

Posted on 2000-03-09
5
139 Views
Last Modified: 2010-05-02
Can anyone please tell me how I should do this. I want to read the filename and the filesize. I want it to loop until it finds a filesize greater than 25K, it will then pop up a message box. I want this to loop to find all the filesize over 25K. Thanks
0
Comment
Question by:gabedc
  • 2
  • 2
5 Comments
 
LVL 43

Accepted Solution

by:
TimCottee earned 150 total points
ID: 2601222
This uses the FileSystemObject in Microsoft Scripting Runtime - add a reference to it in your project Add a textbox called txtPathTo, command button called cmdSearch an list box called lstFiles

Dim fsoFiles As New FileSystemObject
Dim fdcFolders As Folders
Dim fdrFolder As Folder
Dim filFile As File
Dim flaAttribute As FileAttribute

Private Sub cmdSearch_Click()
    Set fdrFolder = fsoFiles.GetFolder(txtPath.Text)
    DrillDown fdrFolder
End Sub

Private Sub DrillDown(fdrFrom As Folder)
    Dim fdcSubFolders As Folders
    Dim flsMatches As Files
    Dim fdrSubFolder As Folder
    Set fdcSubFolders = fdrFrom.SubFolders
    For Each fdrSubFolder In fdcSubFolders
        DrillDown fdrSubFolder
        Set flsMatches = fdrSubFolder.Files
        For Each filFile In flsMatches
            If filFile.Size > 25 * 1024 Then
                lstFiles.AddItem filFile.Path & ", File Size = " & CStr(filFile.Size)
            End If
        Next
    Next
End Sub

Private Sub txtPathTo_Validate(Index As Integer, Cancel As Boolean)
    If Index = 0 Then
        If Right(txtPathTo(0).Text, 1) <> "\" Then txtPathTo(0).Text = txtPathTo(0).Text & "\"
        On Error GoTo errNoFolder
        Set fdrFolder = fsoFiles.GetFolder(txtPathTo(0).Text)
    End If
    Exit Sub
   
errNoFolder:
    MsgBox "The specified folder does not exist:" & vbLf & txtPathTo(0).Text, vbExclamation
    txtPathTo(0).SetFocus
    Exit Sub
End Sub
0
 
LVL 43

Expert Comment

by:TimCottee
ID: 2601228
Sorry missed that you wanted this as a message box, replace the lstFiles.Additem line with your message box if that is what you want. This code drillsdown all subdirectories from the one you enter
0
 
LVL 4

Expert Comment

by:wqw
ID: 2601289
here is another example without a reference to the scripting library. put a testbox, a listbox and a command button on your form.

Option Explicit

Dim MaxFileSize As Long
Dim SubFolders As Collection

Private Sub Command1_Click()
    Set SubFolders = New Collection
    MaxFileSize = Text1
    Process "C:"
    While SubFolders.Count > 0
        Process SubFolders(1)
        SubFolders.Remove 1
    Wend
End Sub

Sub Process(sFolder As String)
    Dim sFile As String
    On Error Resume Next
    Text1 = sFolder
    DoEvents
    sFile = Dir(sFolder & "\*", vbDirectory)
    While sFile <> ""
        sFile = sFolder & "\" & sFile
        If (GetAttr(sFile) And vbDirectory) <> 0 Then
            If Err.Number = 0 Then
                SubFolders.Add sFile
            End If
        Else
            If FileLen(sFile) > MaxFileSize Then
                List1.AddItem sFile & " - " & FileLen(sFile)
                DoEvents
            End If
        End If
        sFile = Dir
    Wend
End Sub

Enter in textbox the size you are searching for then press button and watch!

HTH,

</wqw>

p.s. it also drills down and adds the files to a listbox.
0
 

Author Comment

by:gabedc
ID: 2602158
Thank you.
0
 

Author Comment

by:gabedc
ID: 2616242
The program works. Thanks Tim and wqw.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now