Re: How can I list the files in a directory and sub directory

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance



This code is awesome. It worked with no modification and solved my problem
with just a few add ons.

Thanks,

Jim Arnold
St Michaels MD
=======================
"Albert D. Kallal" wrote:

> Sure, you can use the following code of mine....
>
> 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
>
> You can of course change the first dir command to only return *.dbf fields.
>
> And, if you need to put the data into a reocrdset, you could go somthing
> like:
>
> dim rst as dao.recordset
> .....
> ....
> set rst = currentdb.OpenReocrdSet("tblDir")
>
> For i = 1 To dlist.Count
> rst.Add
> rst!MyFileName = dlist(i)
> rst.Update
> Next i
>
> Anyway, the above code shell should get you something to work with....
>
> --
> Albert D. Kallal (Access MVP)
> Edmonton, Alberta Canada
> pleaseNOOSpamKallal@xxxxxxx
> http://www.members.shaw.ca/AlbertKallal
>
>
>
.



Relevant Pages

  • Re: exif data from jpgs
    ... Sub dirTest() ... Dim dlist As New Collection ... Dim strTemp As String ... ' now process each folder (recursion) ...
    (microsoft.public.access.modulesdaovba)
  • Re: Calling an MS-DOS command
    ... The first sub shows how to use the routine.... ... Dim dlist As New Collection ... Dim strTemp As String ... Dim vFolderName As Variant ...
    (comp.databases.ms-access)
  • Re: Avoiding multiple queries
    ... Public Sub Get_Display_Group ... Dim bytRecordCount As Byte ... The current Group identifier is held in the ... Albert D. Kallal ...
    (microsoft.public.access.formscoding)
  • Re: How can I list the files in a directory and sub directory
    ... > Dim dlist As New Collection ... > End Sub ... > Dim strTemp As String ... > Dim vFolderName As Variant ...
    (microsoft.public.access.modulesdaovba)
  • Re: Calling an MS-DOS command
    ... The first sub shows how to use the routine.... ... Dim dlist As New Collection ... Dim strTemp As String ... Dim vFolderName As Variant ...
    (comp.databases.ms-access)