Computing.Net > Forums > Programming > searching files for strings in VB6

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

searching files for strings in VB6

Reply to Message Icon

Name: Tony Randal
Date: July 24, 2004 at 08:44:19 Pacific
OS: win 2000
CPU/Ram: P3 64MB
Comment:

I have been using a batch file with findstr to search various files for a specific string and print the file the string is found in.

I am interesed in upgrading this batch file to VB6, but can't find any commmands that will search multiple files and paths.

Can anyone offer assistance?



Sponsored Link
Ads by Google

Response Number 1
Name: Burbble
Date: July 31, 2004 at 15:30:51 Pacific
Reply:

Here's a routine a wrote for someone that might help you accomplish your task (basically it find all files within a directory, and its subdirectories, using a recursive function):

http://www.experts-exchange.com/Q_21033463.html

-----

Dim AllFolders As New Collection

Private Sub GetSubFolders(ByVal Directory As String)
Dim FSO, tmpGet, tmpSub, tmpFolder
Dim CurrentFolders As New Collection

Set FSO = CreateObject("Scripting.FileSystemObject")
Set tmpGet = FSO.GetFolder(Directory)
Set tmpSub = tmpGet.SubFolders

For Each tmpFolder In tmpSub
If Right$(Directory, 1) = "\" Then
AllFolders.Add Directory & tmpFolder.Name
CurrentFolders.Add Directory & tmpFolder.Name
Else
AllFolders.Add Directory & "\" & tmpFolder.Name
CurrentFolders.Add Directory & "\" & tmpFolder.Name
End If
Next

For Each tmpFolder In CurrentFolders
GetSubFolders (tmpFolder)
Next
End Sub

Private Sub GetFiles(ByVal Directory As String)
Dim FSO, tmpGet, tmpSub, tmpFile
Dim CurrentFiles As New Collection

Set FSO = CreateObject("Scripting.FileSystemObject")
Set tmpGet = FSO.GetFolder(Directory)
Set tmpSub = tmpGet.Files

For Each tmpFile In tmpSub
processfile (tmpFile) 'Use your function here, this is the loop for each file
Next
End Sub

Private Sub Form_Load()
Dim tmpFolder

GetSubFolders ("C:\My Music") 'Change this path to whatever you need

For Each tmpFolder In AllFolders
GetFiles tmpFolder
Next
End Sub

-----

Good luck :-)

-Burbble


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Programming Forum Home


Sponsored links

Ads by Google


Results for: searching files for strings in VB6

Batch file- read string in txt file www.computing.net/answers/programming/batch-file-read-string-in-txt-file/15532.html

search for string in batch www.computing.net/answers/programming/search-for-string-in-batch/16124.html

Searching for Strings www.computing.net/answers/programming/searching-for-strings/19708.html