Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Import Filenames with Shell DIR command

2 views
Skip to first unread message

Alan Z. Scharf

unread,
Nov 8, 2003, 3:47:29 PM11/8/03
to
I need to import filenames from a directory into an Access table.

How can I do this with the Shell command using DIR?

I've been using File System Object, but that is too slow getting 4,000 file
names over my netowrk.

Thanks.

Alan

___________________________
Alan Z. Scharf
GrapeVine Systems
New York City


Joe Fallon

unread,
Nov 8, 2003, 4:21:08 PM11/8/03
to
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

"Alan Z. Scharf" <asc...@grapevines.com> wrote in message
news:uah1Hmjp...@TK2MSFTNGP12.phx.gbl...

0 new messages