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

convert .txt to .dbf

Status
Not open for further replies.

borsker

Programmer
Jul 24, 2002
147
US
another convertion problem:
how can i convert a .txt file to a .dbf if i know the file is tab delimited. I have been importing it in through the wizard, however if there is an automated way to do it that would be so awsome.
 
No magic conversion..

if you know the structure of the file then create a table with that (or copy an existing structure created via the wizard)

the syntax for importing would be

sele mytable

appen from myfile.txt deli with tab

and that's about it

mrF
 
mrF,
I know it is tab delimited but i do not know how many fields the file will have. so i could do what you said with a generic set struc, but i would be stuck with a lot of extra fields that i do not need. is there a way i can just import it with out the help from an existing table.
 
Without knowing the structure of the tab delimited file there is really no way of getting an exact match with a foxpro table without extraneous fields.

you have some options - all however are manual processes

a: Use the import wizard

b: open the tab delimited file in excel (or similar), make a note of the structure/fields/fieldtypes and create a new table from the table designer then append the tab delimited file in.

C: open the tab delimited file in excel (or similar) and choose SAVE AS DBF 2 (dbase2 table)

MrF


 
Borsker,

I suppose you could write a little program that goes something like this:

lcStr = FILETOSTR("MyTextFile")
ALINES(laArray,lcStr)
lnCount = OCCURS(laArray(1),CHR(9))

That will tell you (in lnCount) how many tabs there are in(the first line of) the file. You could then use CREATE TABLE to create a table with that number of fields, and then go ahead and do the APPEND FROM.

It would make an interesting programming exercise, but I think, on balance, that Mr F's ideas would be more useful.

Mike


Mike Lewis
Edinburgh, Scotland
 
Actually I like the array/create table idea

it would work with files without knowing the structure, some manual intervention may be required regarding field types/names/sizes.

For a general import with field names F1,F2 etc all character 254 characters wide - you import successfully.

It may be inefficient to have such a general structure but would work.

mrf
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top