Requesting a Moderator Please

Would a moderator please contact me using Email Address
rubascin2@...

Shirley Graver
Sys Admin
Rubber Associates Inc.


[Non-text portions of this message have been removed]
I use the "With Application.FileSearch" command a lot in Visual basic to
find files and extract data. However, as our network gets bigger and
bigger, this is taking longer and longer to run. The problem is, I don't
know the full path to where the file is, the file is 7 levels deep and I
know ther first two folder names and then the last 3 fodler names, but not
the middle 2. Does anyone know if there is a way using this command to have
it search:
\\servername\folder_name\[unknown_folder]\[unknown_folder]\folder_name\
folder_name\folder_name\filename
This example uses the collection object. And the dir statement. Please let
me know if you have any questions regarding the code, or how to implement it
into your project. Depending on the application, you may want to
encapsulate it into a subroutine or function, but that's up to you

to accomodate for future upgrades and file relocation, I like to store file
paths and such in a configuration file in the same directory as the
application (app.path), and read those values in at runtime. upon server
upgrade, you don't have to recompile the program, you just change the path.
This example omits that functionality, for brevity.


-Thaddeus

'BEGIN CODE

'THIS EXAMPLE ASSUMES THAT filetofind AND rootpath ARE SET TO CORRECT
'VALUES, AND THAT searchresult IS NESTED EXACTLY TWO LEVELS UNDER
''THE ROOT PATH.
Private Sub main()
Dim Dirs1 As New Collection
Dim Dirs2 As New Collection
Dim foundfiles As New Collection

Dim filetofind As String
Dim rootpath As String
Dim currentdir As Variant
Dim currentdir2 As Variant
Dim searchresult As Variant

'SET THESE PATHS APPROPRIATELY
filetofind = "folder_name\folder_name\....\folder_name\filename"
rootpath = " \\servername\...\folder_name
<file://\\servername\...\folder_name> "

'creates a list of directories under the root path'
'the full path is stored, including the root path

On Error Resume Next 'Ignore any Errors the DIR statement makes.
searchresult = Dir(rootpath + "\*.", vbDirectory)
If searchresult <> "" Then

Do
If Mid(searchresult, 1, 1) <> "." Then
Dirs1.Add (rootpath + "\" + searchresult)
End If
searchresult = Dir
Loop While searchresult <> ""
Else
MsgBox ("Root Path '" + rootpath + "' does not exist")
End
End If
'creates a list of directories under the previous list

For Each currentdir In Dirs1
On Error Resume Next
searchresult = Dir(currentdir + "\", vbDirectory)
If searchresult <> "" Then

Do
If Mid(searchresult, 1, 1) <> "." Then _
Dirs2.Add (currentdir + "\" + searchresult)
searchresult = Dir
Loop While searchresult <> ""

End If
Next currentdir

For Each currentdir In Dirs2
searchresult = Dir(currentdir + "\" + filetofind)
If searchresult <> "" Then
foundfiles.Add currentdir + "\" + filetofind
End If
Next currentdir

If foundfiles.Count > 0 Then
For Each searchresult In foundfiles
'do what ever you want to the found files

MsgBox searchresult
Next searchresult
Else
'you could alternatively set a boolean
'value denoting file wasn't found
MsgBox (filetofind + " was not found.")
End If

End Sub


-----Original Message-----
From: sarah.vareschi@... [ mailto:sarah.vareschi@...
<mailto:sarah.vareschi@...> ]
Sent: Tuesday, February 12, 2002 10:13 AM
To: vantage@yahoogroups.com
Subject: [Vantage] [Off-topic] Visual Basic File Search



I use the "With Application.FileSearch" command a lot in Visual basic to
find files and extract data. However, as our network gets bigger and
bigger, this is taking longer and longer to run. The problem is, I don't
know the full path to where the file is, the file is 7 levels deep and I
know ther first two folder names and then the last 3 fodler names, but not
the middle 2. Does anyone know if there is a way using this command to have
it search:
\\servername\folder_name\[unknown_folder]\[unknown_folder]\folder_name\
folder_name\folder_name\filename


Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must have
already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder and
Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/
<http://groups.yahoo.com/group/vantage/files/> .
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
<http://groups.yahoo.com/group/vantage/messages>
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/links
<http://groups.yahoo.com/group/vantage/links>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
<http://docs.yahoo.com/info/terms/>





[Non-text portions of this message have been removed]
Thad, You are a genius!!! If I told you how long I have been trying to
figure out how to do this.......THANK YOU!!!!

My little program was taking 2-4 minutes to find the files by searching the
entire directory, this has dramatically reduced that!

I am fairly new to visual basic, just sort of been learning it through the
help files and I have never even seen most of the commands you used. Now
that this works, I'm trying to understand it, but it is over my head so I
need some more time with it.

THANK YOU SO MUCH FOR SHARING YOUR EXPERTISE, YOU HAVE NO IDEA HOW MUCH YOU
HELPED ME!!!!



[Non-text portions of this message have been removed]
Try this instead. All you have to understand is the sub main. Just make
sure that the findfiles function is in one of the modules in the project. -
Thaddeus

'CODE BEGINS


Sub main()

Dim foundfiles As Collection
Dim currentfile As Variant

Set foundfiles = findfiles("\\FS1\OLD-I", _
"work\effectivity\effectivity.vbp")

'make sure to check the count before
'accessing the values in the object
If foundfiles.Count > 0 Then
For Each currentfile In foundfiles
MsgBox currentfile
Next currentfile
Else
MsgBox ("file not found.")
End If

End Sub



'just place this sub in any of the public
'modules in the project
public Function findfiles(rootpath As String, _
filetofind As String) As Collection

Dim Dirs1 As New Collection
Dim Dirs2 As New Collection
Dim foundfiles As New Collection

Dim currentdir As Variant
Dim currentdir2 As Variant
Dim searchresult As Variant
'SET THESE PATHS APPROPRIATELY

'create a list of directories under the root path'
'the full path is stored, including the root path
On Error Resume Next
searchresult = Dir(rootpath + "\*.", vbDirectory)
If searchresult <> "" Then

Do
If Mid(searchresult, 1, 1) <> "." Then
Dirs1.Add (rootpath + "\" + searchresult)
End If
searchresult = Dir
Loop While searchresult <> ""
Else
MsgBox ("Root Path '" + rootpath + _
"' does not exist")
End
End If
'create a list of directories under the
'previous list

For Each currentdir In Dirs1
On Error Resume Next
searchresult = Dir(currentdir + "\", vbDirectory)
If searchresult <> "" Then

Do
If Mid(searchresult, 1, 1) <> "." _
Then Dirs2.Add (currentdir + "\" + _
searchresult)
searchresult = Dir
Loop While searchresult <> ""

End If
Next currentdir

For Each currentdir In Dirs2
searchresult = Dir(currentdir + "\" + filetofind)
If searchresult <> "" Then
foundfiles.Add currentdir + "\" + filetofind
End If
Next currentdir

Set findfiles = foundfiles

End Function




-----Original Message-----
From: sarah.vareschi@... [mailto:sarah.vareschi@...]
Sent: Tuesday, February 12, 2002 12:35 PM
To: vantage@yahoogroups.com
Subject: RE: [Vantage] [Off-topic] Visual Basic File Search


Thad, You are a genius!!! If I told you how long I have been trying to
figure out how to do this.......THANK YOU!!!!

My little program was taking 2-4 minutes to find the files by searching the
entire directory, this has dramatically reduced that!

I am fairly new to visual basic, just sort of been learning it through the
help files and I have never even seen most of the commands you used. Now
that this works, I'm trying to understand it, but it is over my head so I
need some more time with it.

THANK YOU SO MUCH FOR SHARING YOUR EXPERTISE, YOU HAVE NO IDEA HOW MUCH YOU
HELPED ME!!!!



[Non-text portions of this message have been removed]



Useful links for the Yahoo!Groups Vantage Board are: ( Note: You must have
already linked your email address to a yahoo id to enable access. )
(1) To access the Files Section of our Yahoo!Group for Report Builder and
Crystal Reports and other 'goodies', please goto:
http://groups.yahoo.com/group/vantage/files/.
(2) To search through old msg's goto:
http://groups.yahoo.com/group/vantage/messages
(3) To view links to Vendors that provide Vantage services goto:
http://groups.yahoo.com/group/vantage/links

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/