Dir function problems

T

thriveni

I use access 2000.
I have a Function that uses to DIR function to locate some
folders, and then have another Function called from within
the loop of Dir, to do further processing on each these
folders. however the DIR loop exits after the first folder
and does not loop through. could this be because the
called Function uses the Filesearch object to retrieve
certain files ? If this Function is not called within the
DIR loop, the loop actually finds all the folders. I have
posted my code below. any help will be appreciated

Function process_source_dirs(myPath1 As String) As Boolean
Dim myName As String, mypath1 As String
Dim ret_val As Boolean, test_name As String
Dim county_path As String
Dim i As Integer
i = 1

myName = Dir(mypath1, vbDirectory) ' Retrieve the first
entry.
Do While myName <> "" ' Start the loop.
' Ignore the current directory and the encompassing
directory.
If myName <> "." And myName <> ".." Then
' Use bitwise comparison to make sure MyName is a
directory.
If (GetAttr(mypath1 & myName) And vbDirectory) =
vbDirectory Then
county_path = myPath & date_dir(i) & "\" & myName
get_county_code (myName)
'call the main function to go through each of
these directories
ret_val = getsubdirs(county_path) ' PROBLEM
here : does not loop through the while if this call is made

End If ' it represents a directory.
End If
myName = Dir ' Get next entry.
Wend

process_source_dirs = ret_val
End Function

Function getsubdirs(myPath As String) As Boolean
Dim fs As FileSearch
Dim intI As Integer
Set fs = Application.FileSearch
Dim myfile As TextStream
Dim book_num As Integer
Dim destination_image_name As String
Dim ret_val As Boolean
Dim logfile_name As String

With fs
.NewSearch
.filename = "*.tif"
.LookIn = myPath
.SearchSubFolders = True
.Execute

count = .FoundFiles.count
For intI = 1 To .FoundFiles.count
myPath = .FoundFiles.Item(intI)
.some processing here ...
'MsgBox myPath

Next
End With
 
A

Albert D. Kallal

What I would do is simply build up a list of folders first..and THEN call
you code.

Below is a routine that returns all folders and sub-folders.

In fact, the routine below returns all files...but it is a simple matter to
modify the code to return all folders.

So, build the list of folders first...and then you should be ok...

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top