Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Converting a UNIX file
Message
De
15/11/1999 07:34:39
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Autre
Divers
Thread ID:
00291177
Message ID:
00291187
Vues:
26
Ohh here is a more detailly commented version :
function Pipe2Comma
lparameters lcFileName,lcOutFile
handlein = fopen(lcFileName) && Open input file
lnSize = fseek(handlein,0,2) && Get size 
* fseek(filehandle, 0, 2) seeks to EOF 
* and returns byte offsett which is filesize
=fseek(handlein,0,0)         && Reset file pointer to byte offsett 0 - BOF
handleout = fcreate(lcOutFile) && Create output file

lcContent = fread(handlein, lnSize)  && Read content to a string
lcPipe2Comma = chrtran(lcContent, "|", ",") && Convert pipes to commas
=fwrite(handleout, lcPipe2Comma, lnSize) && Write to output file
* In previous version above 3 lines were combined to one line

=fclose(handlein)    && Close files
=fclose(handleout)
Cetin

>Thanks Cetin
>
>I don't quite understand how it works - but it does!
>
>Chris
>
>
>>>Hi all
>>>
>>>I've been asked to convert an old UNIX text file which has fields delimited by pipes ("|") - YUK...
>>>
>>>The file does not contain fixed field lengths so I don't think that the approach I've used before :
>>>
>>> mfileopen=FOPEN("&mfilenam")
>>> USE mytable
>>> DO WHILE !FEOF(mfileopen)
>>> etc
>>> etc
>>> etc
>>>
>>>...then using the SUBSTR command will work as the field lengths vary. The only solution I can see is to somehow strip out the "|" and replace them with "," so I can import the file into a table.
>>>
>>>Does anyone have any ideas on how I can achieve this????
>>>
>>>Regards
>>>
>>>Chris Kable
>>>FuelTrac
>>
>>
Chris,
>>If you think stripping out "|" will do it then yu could do it like this :
>>
lcFileName = "mytext.txt"
>>lcOutFile = "myouttext.txt"
>>handlein = fopen(lcFileName)
>>lnSize = fseek(handlein,0,2) && Get size
>>=fseek(handlein,0,0)         && Rewind to top
>>handleout = fcreate(lcOutFile)
>>=fwrite(handleout, chrtran(fread(handlein, lnSize), "|",","), lnSize)
>>=fclose(handlein)
>>=fclose(handleout)
In VFP6 you could also use FILETOSTR() and STRTOFILE().
>>Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform