Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading in an ascii file with FOPEN()
Message
From
05/03/1999 02:39:00
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
 
To
04/03/1999 23:08:28
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00194312
Message ID:
00194338
Views:
23
>I need to read in a ascii file and do a string search on each line and
>denpending on what is found with the string search, I will write out to another ascii file. The form will be:
>open first ascii file
>open second ascii file
>do while .t.
> read in a line of the first ascii
> if search criteria is met
> write out a line to the second ascii file
> else
> loop
>endif
>endo
>
>I will then do a APPEND FROM to bring the second ascii file into a vfp dbf. Any ideas?
*tcInFile = "infile.txt"
*tcOutFile = "outfile.txt"
*tcSearchStr = "searchme"
function In2Out
parameters tcInFile, tcOutFile, tcSearchStr
#define MAXSIZE 1024
* MAXSIZE is maxlen for a line
local lnInHandle, lnOutHandle, lnSize
lnInHandle = fopen(tcInFile) && Open input
lnSize = fseek(lnInHandle,0,2) && Get file size seeking to end
=fseek(lnInHandle,0,0) && Reset file pointer to beginning - starts at 0 offsett
lcContents = fread(lnInHandle,lnSize) && Read whole file
if occurs(lcSearchStr,lcContents) = 0
  messagebox("Search string not found.")
  =fclose(lnInHandle) && Close file
  return
endif
=fseek(lnInHandle,0,0) && Reset file pointer to beginning - starts at 0 offsett
lnOutHandle = fcreate(tcOutFile)  && Create out file
do while !feof(lnInHandle) && Do while !eof
    lcLine = fgets(lnInhandle,MAXSIZE) && Read a line
    if tcSearchStr $ lcLine
       =fputs(lnOutHandle,lcLine, MAXSIZE)  && Write to out file
    endif
enddo
=fclose(lnInHandle)  && Close in file
=fclose(lnOutHandle) && Close out file
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform