Link to home
Start Free TrialLog in
Avatar of Niharika
Niharika

asked on

list Files with particular extension without using file list box

How to list Files with particular extension in a directory without using file list box?
Avatar of bobbit31
bobbit31
Flag of United States of America image

here is an example that lists all "txt" files:

Dim myPath As String
Dim myName As String

myPath = "C:\my documents\"

myName = Dir(myPath & "*.txt")   ' Retrieve the first entry.
Do While myName <> ""   ' Start the loop.
   Debug.Print myName
   myName = Dir   ' Get next entry.
Loop
ASKER CERTIFIED SOLUTION
Avatar of muskad202
muskad202

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Naveen Swamy
Naveen Swamy

   Dim DirName As String   ' Declare variables.
    DirName = Dir(Path, 6)          ' Get first file name.
    Do While DirName <> ""
        If DirName <> "." And DirName <> ".." Then
           lstbox1.AddItem DirName ' Put Filename in list box.
        End If
          DoEvents
        End If
        DirName = Dir             ' Get another file name.
    Loop

hope this helps u,

Rgds,
Navstar16
sorry i forgot to tell u
paths is actually ur dir path + file name or file patttern

eg. "c:\windows\*.dll"
or
app.path & "\*.txt"

Rgds,
Navstar16