source code for seaching in vb5

Can anyone give me a hand to write a seaching program in visual basic?
Who is Participating?
viktornetConnect With a Mentor Commented:
Here is an example for searching folders.... a few minors changes and you will get it to work for files...

Write a batch file taht redirects a dir statment to a file.
Then open that file and read the information line by line using line input util you find the information you  want.
Searching for files? In multiple folders? I have written some code that searches and returns all files in a folder and it's sub folders, interested?
7 new features that'll make your work life better

It’s our mission to create a product that solves the huge challenges you face at work every day. In case you missed it, here are 7 delightful things we've added recently to monday to make it even more awesome.

Marktalbot.. and then a Pascal program to read the file the dir batch file returns.
use FileFindFirst() and FileFindNext()

If you need more HANDm, hehe ;)), lemme know...

chkwahAuthor Commented:
I need an example of the source code
Here's code to list all files in a directory including subdirectories (if you want):

This function will return True if the listing was successful, false otherwhise.

Paramenters in:
   Path = the directory you want to search
   av_Array() = the array you want to fill with all the filenames
   Recursive = boolean value that is True if you want to search all subdirectories, false otherwhise
   x = Don't do anything with this, it's only used in recursive calling
   StartDir = Don't do anything with this either, it's only used in recursive calling
   IncludePaths = if you only want to get the filenames you set this to False but default value is True (you will get full pathnames)

Function ListFiles(ByVal Path As String, ByRef av_Array() As String, Recursive As Boolean, Optional ByRef x As Double = 0, Optional StartDir As Boolean = True, Optional IncludePaths As Boolean = True)

  Dim MyName  As String
  Dim MyDir() As String
  Dim MyDirNr As Integer
  Dim a       As Integer
  MyDirNr = 0
  ReDim MyDir(0)
  If (x = 0) Then
    ReDim av_Array(0)
    Path = sAddDirSep(Path)
  End If
  On Error GoTo ErrorHandler
  MyName = Dir$(Path + "*.*", vbDirectory + vbArchive + vbHidden + vbReadOnly + vbSystem)
  Do While MyName <> ""
    If MyName <> "." And MyName <> ".." Then
      If (GetAttr(Path & MyName) And vbDirectory) <> vbDirectory Then
        If (x Mod 10 = 0) Then
          ReDim Preserve av_Array(x + 10)
        End If
        x = x + 1
        If IncludePaths Then
          av_Array(x) = Path + MyName
          av_Array(x) = MyName
        End If
        ReDim Preserve MyDir(UBound(MyDir) + 1)
        MyDirNr = MyDirNr + 1
        MyDir(MyDirNr) = MyName
      End If
    End If
    MyName = Dir
  If Recursive Then
    For a = 1 To MyDirNr
      If Not ListFiles(Path + MyDir(a) + "\", av_Array(), True, x, False, IncludePaths) Then GoTo ErrorHandler
  End If
  If StartDir Then ReDim Preserve av_Array(x)
  ListFiles = True
  Exit Function
  ListFiles = False

End Function

Just to mention.... in order to change the folder searching example to file searching, you simply have to check for faDirectory which is a constant, and if it is then you simypl recursivly call that function on the directory you've found... as simple as that. :)
Hmm i forgot the sAddDirSep function it's supposed to look something like this

Function sAddDirSep(Text as String) As String

  sAddDirSep = IIF(Right$(Text, 1) = "\", Text, Text & "\")

End Function

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.