Hello every one
we want to show a drive contains files and folder
i mean which files in a drive
example
we use a label1 and we want to my C:\ drive containg files

Dani AI

Generated

To follow up on 's goal (show file count on a drive, a progress bar, and an ETA) and the thread prompt from , a practical, reliable pattern is a two-pass scan: first recursively count all files to set ProgressBar.Max, then walk files again to process and update ProgressBar.Value and an ETA computed from elapsed time per file. The snippet below uses late-bound Scripting.FileSystemObject (no project reference required) and skips folders it cannot open.

Private Declare Function GetTickCount Lib "kernel32" () As Long

Private totalFiles As Long
Private processedFiles As Long
Private startTick As Long
Private fso As Object

Private Function CountFiles(folderPath As String) As Long
    Dim folder As Object, f As Object, sf As Object, cnt As Long
    On Error Resume Next
    Set folder = fso.GetFolder(folderPath)
    If folder Is Nothing Then Exit Function
    For Each f In folder.Files
        cnt = cnt + 1
    Next f
    For Each sf In folder.SubFolders
        cnt = cnt + CountFiles(sf.Path)
    Next sf
    CountFiles = cnt
End Function

Private Sub ProcessFiles(folderPath As String)
    Dim folder As Object, f As Object, sf As Object
    On Error Resume Next
    Set folder = fso.GetFolder(folderPath)
    If folder Is Nothing Then Exit Sub
    For Each f In folder.Files
        processedFiles = processedFiles + 1
        UpdateUI processedFiles
        ' example action: ListBox1.AddItem f.Path
        DoEvents
    Next f
    For Each sf In folder.SubFolders
        ProcessFiles sf.Path
    Next sf
End Sub

Private Sub UpdateUI(processed As Long)
    Dim elapsedMs As Long, estMs As Double, remSec As Long
    If totalFiles = 0 Then Exit Sub
    elapsedMs = GetTickCount() - startTick
    If processed > 0 Then estMs = (elapsedMs / processed) * (totalFiles - processed) Else estMs = 0
    remSec = CLng(estMs / 1000)
    Label1.Caption = Format$(remSec \ 3600, "00") & ":" & Format$((remSec Mod 3600) \ 60, "00") & ":" & Format$(remSec Mod 60, "00")
    ProgressBar1.Min = 0: ProgressBar1.Max = totalFiles: ProgressBar1.Value = processed
End Sub

Private Sub StartScan()
    Set fso = CreateObject("Scripting.FileSystemObject")
    totalFiles = CountFiles("C:\")
    processedFiles = 0
    startTick = GetTickCount()
    ProgressBar1.Min = 0: ProgressBar1.Max = IIf(totalFiles = 0, 1, totalFiles)
    ProcessFiles "C:\"
    Label1.Caption = "Done"
End Sub

Notes and practical tips:

  • Scanning an entire drive can take a long time and will hit permission-protected folders; the code uses On Error Resume Next to skip those. Log Err.Number if you need diagnostics.
  • To reduce UI overhead, call UpdateUI only every N files (e.g., every 25 or 50) instead of on every file. That speeds the scan.
  • If the form still becomes unresponsive, process chunks via a Timer or move the work into a COM worker (VB6 has no safe native threads).
  • If SearchFile.ocx must be used, apply the same two-pass idea (count first, then process while updating UI).

Recommended Answers

All 6 Replies

How far you doing this? post your code. show some effort first.

Hello jx man
acually we want to show a drive files amount .

ok we tell you what i do ?
we make a pc cleaner software and
acually we use a searchfile.ocx and search files in any directory
but i my problem is it . we use a loading progress bar with him when we click search files then
progressbar is start when searching is complete then progressbar is stop
second thing a label show the estimated time which time to complete the search
that's it

So, how far you write a codes to show files in drive?

we cannot write any code to show files in drive
if you have any code so please give me thanks

Give your effort first. then i (and other members) will help you.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.