Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Import text files and path names from serveral folders?

Status
Not open for further replies.
Aug 23, 2001
1
CA
Hello Everyone,
I have files named "Dir_id.dat" located in each directory which contains the description of the particular folder in a single text line. What I need is a function to create a table which dumps the contents of the "Dir_id.dat" in the first field, and writes the path of the directory into the second field. I'm new to VB so I'm having some trouble figuring out the function. Any suggestions?

Buster2
 
Buster,

Are all of the directories on the same level (i.e. are they all under a single master directory or drive letter?) If so, you can do the following:

dim db as Database
dim rst as Recordset
dim intFile as Integer
dim strFolder as String
dim strRecord as String

' Create the new table
DoCmd.RunSQL "CREATE TABLE tblDirectories (Description TEXT, Directory TEXT);"

' Open the new table
Set db = Currentdb()
set rst = db.OpenRecordset("tblDirectories")

strFolder = Dir("Parentfolder\*.*",vbDirectory) ' find the first directory under the parent folder
While strFolder <> &quot;&quot;
' Read the contents of the dir_id.dat file in that folder
intFile = FreeFile
Open strFolder & &quot;\dir_id.dat&quot; for Input AS intFile
Line Input #intFile,strRecord
Close intFile

' Create a table record in the new table
rst.AddNew
rst!Description = strRecord
rst!Directory = strFolder
rst.Update

' Get the next folder name within the parent directory
strFolder = Dir
Wend

' close the table
rst.Close
Set db = Nothing


I may have skimped on some of the steps, but I hope you'll get the idea.

Wally
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top