Loop through a directory

S

SHIPP

How can I loop through a directory and put into a table the file name of say
anything that begins with abc*.txt? I am using Access 2003.
 
K

Ken Snell \(MVP\)

Loop through a directory:

Dim strFile As String
Const strPath As String = "C:\YourFolder\"
strFile = Dir(strPath & "abc*.txt")
Do While strFile <> ""
' strFile contains the file name (e.g., abcFirstFile.txt)
' you can do what you want with it and strPath
' ( put code steps here )
'
' ( end of your code steps )
' read name of next file
strFile = Dir()
Loop


Do you know how to open a recordset and write data to a table?
 
S

SHIPP

Worked like a dream. Thank you.



--
M. Shipp


Ken Snell (MVP) said:
Loop through a directory:

Dim strFile As String
Const strPath As String = "C:\YourFolder\"
strFile = Dir(strPath & "abc*.txt")
Do While strFile <> ""
' strFile contains the file name (e.g., abcFirstFile.txt)
' you can do what you want with it and strPath
' ( put code steps here )
'
' ( end of your code steps )
' read name of next file
strFile = Dir()
Loop


Do you know how to open a recordset and write data to a table?
 
Top