|
-
Nov 21st, 2005, 11:07 AM
#1
Thread Starter
Lively Member
File Search
How would i search for a file by it's extension i.e .doc and have all the results be displayed in a list box?
Carl
-
Nov 21st, 2005, 11:09 AM
#2
Re: File Search
search 1 folder? entire drive?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 21st, 2005, 11:12 AM
#3
Re: File Search
 Originally Posted by VB4Eva
How would i search for a file by it's extension i.e .doc and have all the results be displayed in a list box?
Carl
See Post #7 in this thread which is just a couple of threads below this one.
-
Nov 21st, 2005, 11:20 AM
#4
Re: File Search
the below code will search entire drive for whatever you type into text1...
Listing the results in a listbox... (Allows wildcards )
so search for *.jpg will find any JPG files
VB Code:
Dim FileName As String
Public Function RecurseFolderList(FolderName As String) As Boolean
On Error Resume Next
Dim fso, f, fc, fj, f1
Set fso = CreateObject("Scripting.FileSystemObject")
If Err.Number > 0 Then
RecurseFolderList = False
Exit Function
End If
On Error GoTo 0
If fso.FolderExists(FolderName) Then
Set f = fso.GetFolder(FolderName)
Set fc = f.Subfolders
Set fj = f.Files
For Each f1 In fc
RecurseFolderList (f1)
Next
For Each f1 In fj
Me.Caption = f1
If f1 Like FileName Then
List1.AddItem f1
End If
DoEvents: DoEvents
Next
Set f = Nothing
Set fc = Nothing
Set fj = Nothing
Set f1 = Nothing
Else
RecurseFolderList = False
End If
Set fso = Nothing
End Function
Private Sub Command1_Click()
FileName = Text1
RecurseFolderList "C:\"
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 22nd, 2005, 06:02 AM
#5
Thread Starter
Lively Member
Re: File Search
Thanks for all of your help but i get this error when i try it:
Carl
-
Nov 22nd, 2005, 06:47 AM
#6
Re: File Search
 Originally Posted by VB4Eva
Thanks for all of your help but i get this error when i try it:
Carl
What error do you get?
-
Nov 22nd, 2005, 08:25 AM
#7
Thread Starter
Lively Member
Re: File Search
Run Time Error "70"
Permission Denied.
-
Nov 22nd, 2005, 08:35 AM
#8
Re: File Search
do u have any security on any of the folders?
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 22nd, 2005, 08:36 AM
#9
Re: File Search
 Originally Posted by VB4Eva
Run Time Error "70"
Permission Denied.
Are these network folders?
-
Nov 22nd, 2005, 09:00 AM
#10
Thread Starter
Lively Member
Re: File Search
I'm using the code on my college network. But it should not stop it from working should it?
-
Nov 22nd, 2005, 09:06 AM
#11
Re: File Search
it will cause problems when it hits a folder that u do not have permission to view..
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Nov 22nd, 2005, 10:36 AM
#12
Frenzied Member
Re: File Search
On error goto errHandler...
and a bit lower....
errHandler:
if Err.number = 70 then
'Log the event ?
Resume next
end if
-
Nov 22nd, 2005, 04:21 PM
#13
Thread Starter
Lively Member
Re: File Search
Hi there guys, it works now although it does not search for *.doc files. When i try it, it lists every single file on my hard drive.
Is there anyway i can fix this. Also, how would i get the number of items in a list box to display in a label? Also when it has finished searching all the files on my drive how will i stop it from looping?
Sorry about all the questions i'm just curious. You don't have to help if you do not want too 
Carl
Last edited by VB4Eva; Nov 22nd, 2005 at 04:26 PM.
-
Nov 22nd, 2005, 04:26 PM
#14
Re: File Search
This is how I did it:
VB Code:
For Each f2 In fj
If LCase(Right(f2.Name, 3)) = "doc" Then
-
Nov 22nd, 2005, 04:34 PM
#15
Re: File Search
each time u "Add" to te listbox
Label1.Caption = List1.Listcount
it should finish all on its on when it completes the search.
no need to worry about that
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
-
Feb 27th, 2006, 03:36 AM
#16
Lively Member
Re: File Search
help pls
i tried the code above and its working my question is how can i view the directory of the file where i found the file
ex.
"d:\test\test.bmp" --> this is what apper in the list box
"d:\test\" --- > this is what i want to appear in the listbox or i want to appear that in another control like label box
thanks!!!!!
sorry for the poor english
Last edited by makmaks; Feb 27th, 2006 at 11:23 AM.
-
Feb 27th, 2006, 08:37 AM
#17
Re: File Search
VB Code:
Private Declare Function ShellEx Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, _
ByVal lpFile As String, ByVal lpParameters As Any, _
ByVal lpDirectory As Any, ByVal nShowCmd As Long) As Long
Private Sub List1_DblClick()
Dim tmp As String
Dim pth As String
tmp = List1.List(List1.ListIndex)
pth = Left(tmp, InStrRev(tmp, "\"))
ShellEx Form1.hwnd, "open", pth, "", "", 1
End Sub
JPnyc rocks!! (Just ask him!)
If u have your answer please go to the thread tools and click "Mark Thread Resolved"
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
|