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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to store file names from directory to dbf

Status
Not open for further replies.

amills

Programmer
May 30, 2003
22
US
I have a folder called f:\convert that is populated with .txt files. How can I have foxpro store the filenames (ex. 123456.txt ) to a dbf file . Ideally, the dbf file ( ex. convert.dbf ) will contain one field that is character type with a length of 10 .


Andy
 
lnFiles = ADIR(laDir,'c:\*.*')

FOR lni = 1 to lnFiles
SELECT myTable
APPEND BLANK
REPLACE myTable.filename with laDir(lni,1)
ENDFOR

* couple of points.

1. I'd be careful with long filenames if you are declaring it as char(10).

2. Insert is more efficient than append, but this example is nice for demonstration purposes...




Jim Osieczonek
Delta Business Group, LLC
 
This is similar to Jim's post, but you may find it a bit more robust when there are no files present. Also, I've added your actual path as well as a memo field to contain the path and filename regardless of how long the path might get.

Brian

CREATE TABLE textfiles (filename c(10),withpath m)

lnFileCnt = ADIR(laFileArray,'f:\convert\*.txt')

IF lnFileCnt > 0
FOR lnFile = 1 TO lnFileCnt
APPEND BLANK
REPLACE filename WITH laFileArray(lnFile,1)
REPLACE withpath WITH FULLPATH(laFileArray(lnFile,1))
ENDFOR
ELSE
WAIT WINDOW "No Files Found" NOWAIT
ENDIF
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top