FileListBpx vs. ?

Is there a way to loop through given folder without using a filelistbox or any other control that you must put on a form?

Thanks,
JP
jrcpAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RuchiCommented:
DriveListBox?
0
mcriderCommented:
Yes, you can use the Dir function
For example:

' Returns filename with specified extension. If more than one *.ini
' file exists, the first file found is returned.
MyFile = Dir("C:\WINDOWS\*.INI")

' Call Dir again without arguments to return the next *.INI file in the
' same directory.
MyFile = Dir


Cheers!
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DrDelphiCommented:
You can use the FindFirstFile,FindNextfile API functions. The declarations are in the API text viewer app that ships with VB.


Good luck!!
0
Determine the Perfect Price for Your IT Services

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden with our free interactive tool and use it to determine the right price for your IT services. Download your free eBook now!

RuchiCommented:
Yes....

This program displays using a Folder object.

Option Explicit                    ' General declaration
Dim mFso As New FileSystemObject   ' General declaration

Private Sub dirBox_Click()
   Dim f As Folder
   
   ' Get a Folder to the selected item
   Set f = mFso.GetFolder(dirBox.List(dirBox.ListIndex))
   
   txtDisplay.Text = ""      ' Clear TextBox
   
   ' Test for the root folder
   If f.IsRootFolder = False Then
      txtDisplay.Text = "Root folder: " & f.IsRootFolder _
                        & vbNewLine & _
                        "Parent Folder: " & f.ParentFolder & _
                        vbNewLine & "Size: " & f.Size
   Else
      txtDisplay.Text = "Root folder: " & f.IsRootFolder
   End If
   
   txtDisplay.Text = txtDisplay.Text & vbNewLine & "Type: " & _
                     f.Type & vbNewLine & _
                     "Short Path: " & f.ShortPath & _
                     vbNewLine & "Path: " & f.Path & _
                     vbNewLine & "Short Name: " & f.ShortName
End Sub
0
RuchiCommented:
This example is from the book.
0
jrcpAuthor Commented:
As for using the Dir Function then how do I know ahead of time how many files are in that dir?
0
KDivadCommented:
You don't need to know ahead of time. You pass the arguements to it to retrieve the first match. Successive calls without parameters will return the next file in the folder matching the parameters. When there are no more matches, Dir returns "".

C:\Folder\
  cloud.bmp
  tree.bmp
  rock.bmp

Dir$("C:\Folder\*.bmp") 'Returns "C:\Folder\cloud.bmp"
Dir$() 'Returns "C:\Folder\tree.bmp"
Dir$() 'Returns "C:\Folder\rock.bmp"
Dir$() 'Returns ""

Hope this helps!
0
mcriderCommented:
You don't know ahead of time...  You would loop through like this to get the number of files... Add the following code to a command button, run the program and watch the debug window:


Private Sub Command1_Click()
    Dim MyFile As String
    Dim iVal As Long
   
    MyFile = Dir("C:\WINDOWS\*.INI")
    Do While Not MyFile = ""
        iVal = iVal + 1
        Debug.Print "Found File #" + CStr(iVal) + ": " + MyFile
        MyFile = Dir
    Loop
    If iVal = 0 Then
        Debug.Print "There were not files found"
    Else
        Debug.Print "There were " + CStr(iVal) + " file found"
    End If
End Sub



Cheers!
0
mcriderCommented:
Thanks for the points! Glad I could help!


Cheers!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.