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

Transferring the names of text files to a *.dbf file 1

Status
Not open for further replies.

german12

Programmer
Nov 12, 2001
563
0
16
DE
I have a directory in which a text file is added every week.
It will look like that:
2401.txt
2402.txt
2403.txt etc.

I would like to automatically transfer this information vertically into a column of the Mydir (c) field with the file names of the *.txt files in a VFP file (mydbf.dbf).

So that's how
Mydbf
Field name Mydir:


2401.txt
2402.txt
2403-txt
etc.
Of course I can
DIR *.txt TO mydir.xxx
code, then I first receive a text file with all the names
but it also contains all the bytes below and the file names are next to each other - so difficult to read because I only need the file names for my Mydbf.dbf.
and inserting via filetostring only gets a few of the textfile-names as the string gets to long with that structure.
Is there an another or easier way?

Thanks
Klaus


Peace worldwide - it starts here...
 
ADIR(), Klaus, there is ADIR to create an array and then you can append from that array into a DBF.

So that's a two-liner (if you don't count the cursor creation), as your DBF already exists:
Code:
Create Cursor directoryfiles (cFilename c(254), nSize I, dLastModifieddate D, cLastmodifiedTime C(8))

ADir(laFiles,Home()+'*.txt')
Append From Array laFiles

Chriss
 
Thanks Chriss,
that is exactly what I want.
Regards
Klaus


Peace worldwide - it starts here...
 
Chriss - what is the meaning of the nSize integer field?
NsizeScreenshot_2024-04-14_010251_i44unj.jpg


Peace worldwide - it starts here...
 
Size means how large a file is, in bytes.

It's documented in the help of ADIR, what the array contains.

If you only need the file names, you can also create a DBF with only the first column, the array has even one more column about file attributes, so I just thought I demonstrate both that
a) you get more info from ADIR
b) you don't need to define a DBF with all columns in the array, appending an array just starts with the first array column and the first DBF column and will also not error if the datatypes don't match, you just won't get values correctly and drop surplus elements, but you're also not forced to use them up. But define the fields of a DBF according to the array definition and you get all info.

Chriss
 
Thanks again, Chriss
and it's ok that you demonstrated more because
in this case the NSize is useful, as I can see that they are all similar - and that should be the case as the files contain table of contents of a magazine.

Klaus


Peace worldwide - it starts here...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top