473,386 Members | 1,715 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Recursive File Search VBA vs VB

Hopefully a stupid question, but it doesn't appear that way. Found an
example of a recursive file search, which is exactly what I want, at
Randy Birch's site (mvps.vbnet), but VBA is just different enough not
to compile.

Has anyone successfully adapted this to VBA? Any suggestions?

(Well, short of "go back to your village!")

thanks!

Pieter

Nov 13 '05 #1
8 13690
pi********@hotmail.com wrote:
Hopefully a stupid question, but it doesn't appear that way. Found an
example of a recursive file search, which is exactly what I want, at
Randy Birch's site (mvps.vbnet), but VBA is just different enough not
to compile.

Has anyone successfully adapted this to VBA? Any suggestions?

(Well, short of "go back to your village!")

thanks!

Pieter


There's more than 1 there, which one?

--
[OO=00=OO]
Nov 13 '05 #2
pi********@hotmail.com wrote:
Hopefully a stupid question, but it doesn't appear that way. Found an
example of a recursive file search, which is exactly what I want, at
Randy Birch's site (mvps.vbnet), but VBA is just different enough not
to compile.

Has anyone successfully adapted this to VBA? Any suggestions?

(Well, short of "go back to your village!")

thanks!

Pieter


There's more than 1 there, which one?

--
[OO=00=OO]
Nov 13 '05 #3
You can adopt the following code that I used in ms-access.

Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #4
You can adopt the following code that I used in ms-access.

Sub dirTest()

Dim dlist As New Collection
Dim startDir As String
Dim i As Integer

startDir = "C:\access\"
Call FillDir(startDir, dlist)

MsgBox "there are " & dlist.Count & " in the dir"

' lets printout the stuff into debug window for a test

For i = 1 To dlist.Count
Debug.Print dlist(i)
Next i

End Sub
Sub FillDir(startDir As String, dlist As Collection)

' build up a list of files, and then
' add add to this list, any additinal
' folders

Dim strTemp As String
Dim colFolders As New Collection
Dim vFolderName As Variant

strTemp = Dir(startDir)

Do While strTemp <> ""
dlist.Add startDir & strTemp
strTemp = Dir
Loop

' now build a list of additional folders
strTemp = Dir(startDir & "*.", vbDirectory)

Do While strTemp <> ""
If (strTemp <> ".") And (strTemp <> "..") Then
colFolders.Add strTemp
End If
strTemp = Dir
Loop

' now process each folder (recursion)
For Each vFolderName In colFolders
Call FillDir(startDir & vFolderName & "\", dlist)
Next vFolderName

End Sub

--
Albert D. Kallal (Access MVP)
Edmonton, Alberta Canada
pl*****************@msn.com
http://www.members.shaw.ca/AlbertKallal
Nov 13 '05 #5
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.

Nov 13 '05 #6
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.

Nov 13 '05 #7
pi********@hotmail.com wrote:
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.


Yes, List1.Rowsource="", shouldn't need to requery as changing the
rowsource automatically does that.

--
[OO=00=OO]
Nov 13 '05 #8
pi********@hotmail.com wrote:
Which one. Sorry, for some weird reason, I can't get the complete web
page address. but it's "Recursive File Search Demo - Multiple File
Types".

I got it to work. Except for the

List1.Clear

line. Apparently, VB6 and VBA are just ever so slightly different to
make porting the code really annoying. I stripped out all the
references to default properties, like .Text for textboxes and it
worked fine except for the List1.Clear. How to do that - I'm not sure
I'm that worried. Maybe set the thing's rowsource to nothing and
requery it... other than that, it seems to be working. If anyone's
interested, I'll post the code. The changes are basically minor.
Remove all references to default properties, change the rowsource type
of the listbox to Value List and away you go.


Yes, List1.Rowsource="", shouldn't need to requery as changing the
rowsource automatically does that.

--
[OO=00=OO]
Nov 13 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: alanwo | last post by:
For recursive search for files, like http://support.microsoft.com/default.aspx?scid=KB;EN-US;306666, it may lead to "out of stack" error if searching too many files, say millions of files. Do you...
6
by: Talin | last post by:
I've been using generators to implement backtracking search for a while now. Unfortunately, my code is large and complex enough (doing unification on math expressions) that its hard to post a...
0
by: pietlinden | last post by:
Hopefully a stupid question, but it doesn't appear that way. Found an example of a recursive file search, which is exactly what I want, at Randy Birch's site (mvps.vbnet), but VBA is just...
3
by: Ameen | last post by:
I am very new to programming and VB.net, and I wrote the code below, but it seem to go on an infinite loop. Please tell me what I am doing wrong. Private Sub search(ByVal indexstart) Pos1 =...
3
by: Robertico | last post by:
I'am new to php and have a question about a recursive file search. I'd like to do a recursive search for jpg-files and add the filenames (full path) to a mysql database. I appreciate any help ! ...
10
by: AsheeG87 | last post by:
Hello Everyone! I have a linked list and am trying to include a recursive search. However, I am having trouble understanding how I would go about that. I don't quite understand a recursive...
9
by: Lloyd Sheen | last post by:
For all those who don't think that a recursive search of files in folders is a good thing in the Microsoft.VisualBasic.FileIO.FileSystem namespace listen to this. I am reorg my mp3 collection. ...
5
by: Jean-Paul Calderone | last post by:
On Wed, 16 Apr 2008 13:18:22 -0700 (PDT), skanemupp@yahoo.se wrote: Function calls (recursive or otherwise) are more expensive than for loops, so the version that replaces recursion with a loop...
0
by: Simon Brunning | last post by:
2008/7/4 Gerhard Häring <gh@ghaering.de>: glob's not recursive AFAIK. This recipe probably still works under Pythion 3K, though: ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.