How to get a list of all the file names in a directory using VB6?

What is the easiest way in VB6 to scroll through all the files in the specified folder directory and get their names?

+6
file directory vb6
source share
4 answers
sFilename = Dir(sFoldername) Do While sFilename > "" debug.print sFilename sFilename = Dir() Loop 
+15
source share
 Dim fso As New FileSystemObject Dim fld As Folder Dim fil As File Set fld = fso.GetFolder("C:\My Folder") For Each fil In fld.Files Debug.Print fil.Name Next Set fil = Nothing Set fld = Nothing Set fso = Nothing 
+9
source share

The DJ solution is simple and effective, it just throws another one if you need a little more functionality that FileSystemObject can provide (a link to Microsoft Scripting Playback time is required).

 Dim fso As New FileSystemObject Dim fil As File For Each fil In fso.GetFolder("C:\").Files Debug.Print fil.Name Next 
+4
source share

create button named = browseButton create filelistbox named = List1

double click on a button in a design

and the code should look like this:

 Private Sub browseButton_Click() Dim path As String path = "C:\My Folder" List1.path() = path List1.Pattern = "*.txt" End Sub 

will execute it now

0
source share

All Articles