Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Reading in an ascii file with FOPEN()
Message
From
05/03/1999 12:35:40
 
 
To
05/03/1999 12:28:28
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
General information
Forum:
Visual FoxPro
Category:
Other
Miscellaneous
Thread ID:
00194312
Message ID:
00194594
Views:
22
>>>>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
>>-------------------
>>Hi Cetin and thanks for the code... it helps... :)
>Hi Robert,
>There is one little thing that I missed in your question :) You would then "append from". Though lowlevel is effective when parsing text files that do not obey a standart format and/or might contain memo also with standart formats you could directly use "append from". If your txt file is just any standart file that could benefit "append from ... type ..." then I would say just add a for clause. You can use filtering while appending :)
>append from myfile.txt for "xx"$mynamefield type sdf
>append from myfile.txt for day(mydate)=12 type sdf
>append from myfile.txt for mysomefield="Reserved" type sdf
>etc are all valid and work :)
>Cetin
------
thanks again.. :)
Robert Keith
Independent Developer
San Antonio, Texas
E-mail address:
rebelrob1@yahoo.com
Previous
Reply
Map
View

Click here to load this message in the networking platform