Disk Directory Structure

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'd like Access to scan a local hard disk and automatically generate tables etc that represent the directories and files. Are there some readily available Access data structures that can be used to get me going
 
Maybe this code can be modified to meet your needs:

How to Add Directory File Names to an Access Table:

Create a table named tblDirectory with 2 fields:
FileName (Text 250)
FileDate (Date/Time)

Call the code below by pressing Ctrl-G to open the debug window and type:
GetFiles("c:\windows\")

Paste this code into a regular module:

Sub GetFiles(strPath As String)
Dim rs As Recordset
Dim strFile As String, strDate As Date

'clear out existing data
CurrentDb.Execute "Delete * From tblDirectory", dbFailOnError

'open a recordset
Set rs = CurrentDb.OpenRecordset("tblDirectory", dbOpenDynaset)

'get the first filename
strFile = Dir(strPath, vbNormal)
'Loop through the balance of files
Do
'check to see if you have a filename
If strFile = "" Then
GoTo ExitHere
End If
strDate = FileDateTime(strPath & strFile)
rs.AddNew
'to save the full path using strPath & strFile
'save only the filename
rs!FileName = strFile
rs!FileDate = strDate
rs.Update

'try for next filename
strFile = Dir()
Loop

ExitHere:
Set rs = Nothing
MsgBox ("Directory list is complete.")
End Sub

--
Joe Fallon
Access MVP



Dominique said:
I'd like Access to scan a local hard disk and automatically generate
tables etc that represent the directories and files. Are there some readily
available Access data structures that can be used to get me going?
 
On my website (see sig below) is a small sample database called
DirectoryList.MDB, which shows one way to do this.

--
--Roger Carlson
www.rogersaccesslibrary.com
Reply to: Roger dot Carlson at Spectrum-Health dot Org

Dominique said:
I'd like Access to scan a local hard disk and automatically generate
tables etc that represent the directories and files. Are there some readily
available Access data structures that can be used to get me going?
 
Roger

You code is very nice. (Although I have had to remove the Environ function call as it seems to cause an unresolved reference error. As I'm only using the database on a Windows 2000 machine, I can hard code the shell command.

In principle I can use your code as my starting point

Thank

Dom
 
Back
Top