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

Having trouble appending from a specific text file 1

Status
Not open for further replies.
Sep 2, 2009
6
US
I usually append ASCII Comma Delimited files into my database. I just got this file that seperates every field with this character | (I belive "|" is called pipe delimited). How do I append this pipe delimited file into my database?

Append from 1.txt type pipe delimited?
 
According to FoxPro help it's:
append from 1.txt type delimited with |
I haven't tried it but you could, (on a copy of course!).

Best of luck,
Roger
 
"I just got this file that seperates every field with this character | "

My first question would be - is this a unique or seldomly occurring issue?

If this was a unique situation, I'd use Notepad or Word on the Input file to Replace all of the pipe delimiters with a comma and then I'd process things as usual.

However if this issue were to be encountered more than seldom....
You can use another APPEND FROM option, but personally I'd work to 'normalize' the input data so that I could use a consistent APPEND FROM command.

You could use something like the following:
Code:
cInputFile = "C:\Temp\Temp.txt"

* --- 'Read' file into string for testing ---
cTestString = FILETOSTR(cInputFile)

* --- Test for Pipe Delimiter ---
IF "|" $ LEFT(cTestString,80)
   * --- Yes Pipe Found, Change Them To Commas ---
   cTestString = STRTRAN(cTestString,"|",",")
   * --- Write Results Back To File ---
   =STRTOFILE(cTestString,cInputFile)
ENDIF

< Now do whatever is normal with file >

Depending on the version of your old non-Visual Foxpro you would have to confirm if it supports the FILETOSTR() and STRTOFILE() functions.
If not, you could always use low-level FOPEN(), FGETS(), FPUTS(), etc. commands to do the same.

Good Luck,
JRB-Bldr
 
It still doesn't work. It is putting all the data in the first field. This is an example of what the data looks like:

James|Carson|811 Inlet Dr|Naples|FL|

I noticed that there are no "" between fields either. Anyone have any suggestions on how to import this type of file?
 
It seems as though the APPEND FROM you are trying is not working as expected.

Have you tried one of my suggestions yet
1. Either modify the input file with WORD or NOTEPAD
or
2. Change the file contents with FP code.

Good Luck,
JRB-Bldr
 
Your problem is that the data isn't _delimited_ with the pipe. It's separated by the pipe character. The APPEND FROM command (and its Help) is quite confused about delimiters vs. separators.

In general, though, for a file to be considered delimited, not only is there a regular separator character, but character fields are surrounded by quotes (or some other character). That's why the commands you're trying are failing.

Tamar
 
[&nbsp;]

It appears that the easiest solution might be to use low level functions to either modify your file into a CSV file OR to dump your data directly into an array.

See this thread ( on how to use a low level file to scrape your data. Modifying it to suit your needs should be relatively trivial once you understand what it is doing.

mmerlinn


"We've found by experience that people who are careless and sloppy writers are usually also careless and sloppy at thinking and coding. Answering questions for careless and sloppy thinkers is not rewarding." - Eric Steven Raymond
 
APPEND FROM <file> | ?
[FIELDS <field list>]
[FOR <expL>]
[[TYPE] [DELIMITED [WITH TAB
| WITH <delimiter>
| WITH BLANK]
| DIF | FW2 | MOD | PDOX | RPD
| SDF | SYLK | WK1 | WK3 | WKS
| WR1 | WRK | XLS]]
Adds records to the end of the current table from another file.

I did not find =STRTOFILE in help of FPW2.6a!

I would try (If I good understand):
1. to create temporary.dbf with one field cTestStr 255 or one MEMO field cTestStr
2. append from file XXXX.txt type sdf (I suppose in the XXXX you have ccc|ccc|ccc|ccc)
3. Then simply
replace all cTestStr with strtran(cTestStr,"|",",")
4. At the end to make text-file from the temporary.dbf

P.S. Maybe you could try it with excel-file??


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top