Results 1 to 12 of 12

Thread: Searching for multiple files on harddrive(s) [Resolved!]

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    71

    Searching for multiple files on harddrive(s) [Resolved!]

    Hello everyone!

    I've searched for this on the forum, but I could only find code for a single file search or extension search.

    I have a database with application titles and their starting executables. I would like an example on how to search all the executable files listed in the database, so I can tell which application is installed on the users harddrives.

    I know it's possible to just use the recursive Dir function on each file seperately, but I think it would take ages if I had to use this with a database with over 100 files to search.

    I've also heard of the FSO, but I've never used it, so I wouldn't know if it's possible with that.

    Can anyone help me with this problem?

    Thanks in advance!

    Dave.
    Last edited by DaveG; Mar 11th, 2003 at 07:17 PM.

  2. #2
    PowerPoster
    Join Date
    Aug 2001
    Location
    new jersey
    Posts
    2,904
    I think you're looking for a simpler solution than is possible.

    Whether you use FSO or dir or whatever, you're going to HAVE to recursively search every directory and compare every EXE file name found to the list of names you are looking for, and yes, for a big hard drive it's going to take a while. There is no magic.

    For executables that register with Windows, I think you can look in the registry somehow, but I can't help you further with that.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    71
    Well, I've tried searching with Dir, and although it takes a few seconds per file to be searched, it does work. I can shorten the search time by asking the user to select a specific directory where (s)he think the apps may be located, but it's not a pretty solution.

    This guy seemed to be working on searching multiple files, but I can't make heads or tails of it...

  4. #4
    Addicted Member TheSarlacc's Avatar
    Join Date
    Aug 2002
    Location
    Somewhere close
    Posts
    185
    why dont you just create an array in VB, then use Dir to map the whole hard drive into the array (you could use a filter so that only .exe files show up), then search the array for an item you are looking for from the database. better to try and use less HDD and more RAM resources as possible since RAM is quicker.
    Get Quoted:

    "If Shane Warne had given his mobile phone to Russell Crowe, neither of them would be in trouble."
    "She has more troubles than a centipede with its legs crossed."
    "For every action, there is an equal and opposite Government program."


  5. #5
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    You can use InStr...

    This is just an example, it will search in the windows directory too see if 4 files are there...
    VB Code:
    1. Private Sub Form_Load()
    2.     Dim aFindFiles(3) As String, sFindFiles As String, File As String
    3.    
    4.     aFindFiles(0) = "NOTEPAD.EXE"
    5.     aFindFiles(1) = "win.ini"
    6.     aFindFiles(2) = "system.ini"
    7.     aFindFiles(3) = "winnt.bmp"
    8.    
    9.     sFindFiles = ";" & Join(aFindFiles, ";") & ";"
    10.     ' sFindFiles will contain   ";NOTEPAD.EXE;win.ini;system.ini;winnt.bmp;"
    11.    
    12.     File = Dir("C:\Windows\*.*", vbArchive + vbHidden + vbReadOnly)
    13.     Do Until File = ""
    14.         If File <> "." And File <> ".." Then
    15.             If InStr(1, sFindFiles, ";" & File & ";", vbTextCompare) > 0 Then
    16.                 Debug.Print "Found file: " & File
    17.             End If
    18.         End If
    19.        
    20.         File = Dir
    21.     Loop
    22. End Sub

  6. #6
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974
    If you are looking for app's that install properly (ie: add themselves to the "add/remove programs" list), you just need to read the registry at this location:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall\


    There are plenty of examples of using the registry all over this site & the rest of the web.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    71
    OK, I've used the Instr() function as you advised, and I've combined it with an FSO, and...it works!

    But... the Instr function will return everything that matches, which means partial names as well (say I'm searching for thisapp.exe, and the FSO lists a file names app.exe, it will give a match.

    Do now, I've added the found files into a hidden flexgrid, and then I search that flexgrid for the proper filenames. So it's not the best solution, but it certainly much better than I came up with

    Thanks!

    Dave.

  8. #8
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    That's why i've put semicollon before and after the file name !

    Just do it exactly the way I've done it in my code example and you'll see it will work...

  9. #9

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    71
    Well, it went from bad to worse I'm afraid....

    I wanted to modify your code, so it would accept an unlimited amount of files, so I made an array. Well, the sFindFiles string didn't accept this, so I made the following code:

    Code:
            If Len(sFindFiles) = 0 Then
                sFindFiles = ";" & rsUpdate.Fields("ExeFile") & ";"
            Else
                sFindFiles = sFindFiles & rsUpdate.Fields("ExeFile") & ";"
            End If
    This works, but sometimes the string of Exe's (;name.exe;name2.exe;name3.exe;) seems to match with directories named '2' or '3'.

    Secondly, I wanted to have a recursive function, so it would search the subfolders of the selected dir too. That's how I got onto the FSO story.

    If it's not to much trouble, could you modify your code to accept an unlimited amount of files, and to search the subfolders too?

    Thanks in advance!

    Dave.

  10. #10
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     Dim SearchResults As New Collection, sPath As Variant
    5.    
    6.     FindMultipleFiles "C:\", "|win.ini|vb6.exe|link.exe|biblio.mdb|msmsgs.exe|winamp.exe|", SearchResults
    7.    
    8.     For Each sPath In SearchResults
    9.         Debug.Print sPath
    10.     Next
    11. End Sub
    12.  
    13. Private Sub FindMultipleFiles(ByVal RootPath As String, ByRef FindFiles As String, ByRef Results As Collection)
    14.     Dim Dirs() As String, FoundDirs As Boolean, K As Long
    15.     Dim currFile As String
    16.    
    17.     If Right(RootPath, 1) <> "\" Then RootPath = RootPath & "\"
    18.     currFile = Dir(RootPath & "*", vbArchive + vbDirectory + vbHidden + vbReadOnly)
    19.    
    20.     Do Until currFile = ""
    21.         If currFile <> "." And currFile <> ".." Then
    22.             If (GetAttr(RootPath & currFile) And vbDirectory) = vbDirectory Then
    23.                 If Not FoundDirs Then
    24.                     ReDim Dirs(0)
    25.                 Else
    26.                     ReDim Preserve Dirs(UBound(Dirs) + 1)
    27.                 End If
    28.                
    29.                 Dirs(UBound(Dirs)) = currFile
    30.                 FoundDirs = True
    31.             ElseIf InStr(1, FindFiles, "|" & currFile & "|", vbTextCompare) > 0 Then
    32.                 Results.Add RootPath & currFile
    33.             End If
    34.         End If
    35.        
    36.         currFile = Dir
    37.     Loop
    38.    
    39.     If FoundDirs Then
    40.         For K = 0 To UBound(Dirs)
    41.             FindMultipleFiles RootPath & Dirs(K), FindFiles, Results
    42.         Next K
    43.     End If
    44. End Sub
    I got those results:
    C:\Program Files\Messenger\msmsgs.exe
    C:\Program Files\Microsoft Visual Studio\VB98\BIBLIO.MDB
    C:\Program Files\Microsoft Visual Studio\VB98\LINK.EXE
    C:\Program Files\Microsoft Visual Studio\VB98\VB6.EXE
    C:\Program Files\Microsoft Visual Studio .NET\Vc7\bin\link.exe
    C:\Program Files\Winamp\winamp.exe
    C:\WINDOWS\win.ini
    C:\WINDOWS\ServicePackFiles\i386\msmsgs.exe

  11. #11
    PowerPoster
    Join Date
    Feb 2002
    Location
    Canada, Toronto
    Posts
    5,803
    I've changed the ";" to "|" because files cannot contain "|", but it can contain ";"... I did not check for that before...

  12. #12

    Thread Starter
    Lively Member
    Join Date
    Feb 2001
    Posts
    71

    YESSS!!!

    THIS IS IT!!!

    Thank you very much!!!

    You just made a friend for life!


    Dave.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width