Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsFormsForms ProgrammingQueriesModules / DAO / VBAReports / PrintingMacrosDatabase DesignSecurityConversionImporting / LinkingSQL Server / ADPMultiuser / NetworkingReplicationSetup / ConfigurationDeveloper ToolkitsActiveX ControlsNew UsersGeneral 1General 2
Access DirectoryToolsTutorialsUser Groups
Related Topics
SQL ServerOther DB ProductsMS OfficeMore Topics ...

MS Access Forum / Modules / DAO / VBA / June 2005

Tip: Looking for answers? Try searching our database.

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

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
felixc36@yahoo.com - 04 Feb 2005 04:19 GMT
Hi,

I have this project where i must read all the files havin a specific extention
(*.mdb for example) in a directory and subdirectories.

I was wondering if that is possible.

What ultimately I am looking for is building a procedure that would have a
root directory and an extention as parameters and then would create a
recordset having the path and filenames of all the files having the extention
in the directory and it's sub directories.

Is that a feasable thing in Access 97?

You can answer me here or at my e-mail address Felixc36NoSPAM@yahoo.com.
(please remove the NoSPAM in the address).

Thank you
Alan Z. Scharf - 04 Feb 2005 06:52 GMT
When you say read, do you mean read data from them or get a listing.

The System File Object will handle many file-related operations.

Alan

> Hi,
>
[quoted text clipped - 14 lines]
>
> Thank you
felixc36@yahoo.com - 04 Feb 2005 13:56 GMT
Thank you for answering....

What I want to do is first to capture the path and flename and utlimately read
the contents of the files for processing.

For example I have the following file structure:
C:\--|
MyDir------------Agency1 ---- 2002--- File1.dbf, file2.dbf
   |                      | --------- 2003---File1.dbf
   |                      |----------- 2004---File1.dbf
   |
   |--------------------Agency2 ---- 2002---File1.dbf, file2.dbf
   |                        |-------- 2003---File1.dbf
   |    
   |---------------Agency3 ---- 2000--- File1.dbf, file2.dbf
                       |----------- 2001---File1.dbf, file2.dbf
                       |------------ 2002--- File1.dbf, file2.dbf

I want to pass as a parameter MyDIR and The DBFextension to a procedure.

What I would want is for the procedure to create a recordset capturing the
path of each files having a dbf extension in a variable.

"C:\Mydir\Agency1\2002\File1.dbf"
"C:\Mydir\Agency1\2002\File2.dbf!"
"C:\Mydir\Agency1\2003\File1.dbf!"
"C:\Mydir\Agency1\2004\File1.dbf!"
"C:\Mydir\Agency2\2002\File1.dbf!"
..

.. and so on.

>When you say read, do you mean read data from them or get a listing.
>
[quoted text clipped - 22 lines]
>>
>> Thank you
Miaplacidus - 04 Feb 2005 15:07 GMT
I have a similar problem, I can use filesearch to get the listing of files
and subdirectories. What Ai want to do first is read the other file
attributes into a table and later, based on file attributes, opent the files
and search for keywords or other information. The end result will be to
create an index of files on the drive with contacts etc.

> Thank you for answering....
>
[quoted text clipped - 54 lines]
> >>
> >> Thank you
Albert D. Kallal - 05 Feb 2005 00:44 GMT
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....

Signature

Albert D. Kallal   (Access MVP)
Edmonton, Alberta Canada
pleaseNOOSpamKallal@msn.com
http://www.members.shaw.ca/AlbertKallal

Miaplacidus - 15 Apr 2005 16:52 GMT
Thanks, that worked, but I would have never glommed it alone. I used that to
create a list of files in a DB. Then I went back and read the list and opened
each file to create a summary of what is in it and also to pick up all the
other file properties. I used Auto summary in word to create a short summary,
and that works OK.  I'm still working on a method for other file types. I'd
like to, for example open a PPT file and step through the text boxes looking
for words that are used frequently (other than prepositions).  I need a
similar method for other file types, like excel.  

Anybody got suggestions, I'm listening.

> Sure, you can use the following code of mine....
>
[quoted text clipped - 68 lines]
>
> Anyway, the above code shell should get you something to work with....
Jim - 16 Jun 2005 06:31 GMT
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
=======================

> Sure, you can use the following code of mine....
>
[quoted text clipped - 68 lines]
>
> Anyway, the above code shell should get you something to work with....
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.