Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

File Size

Posted on 2000-03-09
5
Medium Priority
?
151 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 600 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

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…
Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Suggested Courses

824 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