-
Reading the Contents of a Drive
The functon below loops through a given folder and prints the names of all the .mdb files it contains. What I want to do is to specify a drive and then to loop through each folder in the drive and output the folder name and the names of the fles in each.
Thanks in Advance
Public Function fnScanDir1(strDir As String)
Dim strFileName As String
Dim strDrive As String
Dim mStrFileName As String
strDrive = Left(strDir, 1)
ChDrive strDrive
ChDir strDir
mStrFileName = Dir$("*.mdb")
While Len(mStrFileName) > 0
Debug.Print mStrFileName
mStrFileName = Dir$
Wend
End Function
-
Hi,
Try this code. Sorry about the spacing - I can't figure out how to maintain the spacing in my posts.
Option Compare Database
Option Explicit
Private m_arr_strFolderNames() As String
Public Function ListFiles()
Dim intArrayIndex As Integer, intFolderCount As Integer
ChDrive "C:"
ChDir "C:\"
If PutFolderNamesIntoArray(intFolderCount) Then
For intArrayIndex = 0 To intFolderCount - 1
ListFolderContents m_arr_strFolderNames(intArrayIndex)
Next intArrayIndex
End If
End Function
Private Function PutFolderNamesIntoArray(intNumberOfFoldersFound As Integer) As Boolean
Dim strFolder As String
Dim intCounter As String
strFolder = Dir$("*.", vbDirectory)
intCounter = 0
Do While Len(strFolder) > 0
intCounter = intCounter + 1
ReDim Preserve m_arr_strFolderNames(intCounter) As String
m_arr_strFolderNames(intCounter - 1) = strFolder
strFolder = Dir$
Loop
intNumberOfFoldersFound = intCounter
PutFolderNamesIntoArray = True
End Function
Private Sub ListFolderContents(strFolderName As String)
Dim strFileName As String
Debug.Print strFolderName
strFileName = Dir$(strFolderName & "\*.mdb", vbDirectory)
Do While Len(strFileName) > 0
Debug.Print vbTab & strFileName
strFileName = Dir$
Loop
Debug.Print vbCrLf
End Sub
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
|
|