|
-
Mar 10th, 2003, 07:28 PM
#1
Thread Starter
Lively Member
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.
-
Mar 10th, 2003, 07:59 PM
#2
PowerPoster
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.
-
Mar 10th, 2003, 09:20 PM
#3
Thread Starter
Lively Member
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...
-
Mar 10th, 2003, 10:12 PM
#4
Addicted Member
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."

-
Mar 11th, 2003, 01:22 AM
#5
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:
Private Sub Form_Load()
Dim aFindFiles(3) As String, sFindFiles As String, File As String
aFindFiles(0) = "NOTEPAD.EXE"
aFindFiles(1) = "win.ini"
aFindFiles(2) = "system.ini"
aFindFiles(3) = "winnt.bmp"
sFindFiles = ";" & Join(aFindFiles, ";") & ";"
' sFindFiles will contain ";NOTEPAD.EXE;win.ini;system.ini;winnt.bmp;"
File = Dir("C:\Windows\*.*", vbArchive + vbHidden + vbReadOnly)
Do Until File = ""
If File <> "." And File <> ".." Then
If InStr(1, sFindFiles, ";" & File & ";", vbTextCompare) > 0 Then
Debug.Print "Found file: " & File
End If
End If
File = Dir
Loop
End Sub
-
Mar 11th, 2003, 05:15 AM
#6
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.
-
Mar 11th, 2003, 07:51 AM
#7
Thread Starter
Lively Member
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.
-
Mar 11th, 2003, 01:22 PM
#8
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...
-
Mar 11th, 2003, 05:31 PM
#9
Thread Starter
Lively Member
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.
-
Mar 11th, 2003, 06:00 PM
#10
VB Code:
Option Explicit
Private Sub Form_Load()
Dim SearchResults As New Collection, sPath As Variant
FindMultipleFiles "C:\", "|win.ini|vb6.exe|link.exe|biblio.mdb|msmsgs.exe|winamp.exe|", SearchResults
For Each sPath In SearchResults
Debug.Print sPath
Next
End Sub
Private Sub FindMultipleFiles(ByVal RootPath As String, ByRef FindFiles As String, ByRef Results As Collection)
Dim Dirs() As String, FoundDirs As Boolean, K As Long
Dim currFile As String
If Right(RootPath, 1) <> "\" Then RootPath = RootPath & "\"
currFile = Dir(RootPath & "*", vbArchive + vbDirectory + vbHidden + vbReadOnly)
Do Until currFile = ""
If currFile <> "." And currFile <> ".." Then
If (GetAttr(RootPath & currFile) And vbDirectory) = vbDirectory Then
If Not FoundDirs Then
ReDim Dirs(0)
Else
ReDim Preserve Dirs(UBound(Dirs) + 1)
End If
Dirs(UBound(Dirs)) = currFile
FoundDirs = True
ElseIf InStr(1, FindFiles, "|" & currFile & "|", vbTextCompare) > 0 Then
Results.Add RootPath & currFile
End If
End If
currFile = Dir
Loop
If FoundDirs Then
For K = 0 To UBound(Dirs)
FindMultipleFiles RootPath & Dirs(K), FindFiles, Results
Next K
End If
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
-
Mar 11th, 2003, 06:03 PM
#11
I've changed the ";" to "|" because files cannot contain "|", but it can contain ";"... I did not check for that before...
-
Mar 11th, 2003, 07:15 PM
#12
Thread Starter
Lively Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|