HELP- with open("ab")
--------------A23D4B41DCE6550F0385724E
Content-Transfer-Encoding: 8bit
I'm having trouble with appending a line of test to an existing text file. The
source is a different file.
The target file is opened in 'append' mode open(fn,"ab"). The new line is
appended with
puts(FileToUpdate,UpdateRecord)
The problem is that an ascii 26 (eof) is present as the first byte of the
appended record, so other software cannot see
the appended record(s).
I think the ascii 26 was there to begin with, since subsequent runs of the
program do not have that code as the first
byte of the appended records, only the 1st run.
Is the a way to get rid of the ascii 26 code, or amd I using thw wrong Euphoria
code to do the open or the append?
Any help will be greatly appreciated.
Program is included with sample input and ouput inserted as comments.
Thanks.
Jim
--------------A23D4B41DCE6550F0385724E
name="Update.ex"
Content-Disposition: inline;
filename="Update.ex"
-- update.ex
-- while true do
-- read TODAYS.TXT -- use field 1 (File ID) to select existing history file
-- open named history file
-- append from TODAYS.TXT
-- end while
include file.e
include get.e
with trace
without warning
allow_break(1)
sequence buffer,CodeField,TxtField,String,test,x,YearPart,ReadRecord
integer DirFile,true,false,RecCount,TotRecs,BOF,EOF,RecLen,OK
object Record,wait
atom a,b,c,IsNumeric,z
true = 1
false = 0
buffer = {}
RecCount = 0
-------------------------------------------------------------
-- update daily files with today's data (in TODAYS.TXT. --
------------------------------------------------------------
sequence FileName, Field, WhichFile, UpdateRecord
integer TodaysData, pos, FieldNo, len1, len2, FilesUpdated
object char, RestOfRecord, FileToUpdate, input_string, file_id
-------------------------------------------------
-- unpack Todays.exe in \CANDLES\DOWNLOAD\ --
-------------------------------------------------
system("\\CANDLES\\DOWNLOAD\\TODAYS.EXE",2) -- unpack Todays.TXT
TodaysData = open("\\CANDLES\\DOWNLOAD\\TODAYS.TXT","rb")
if TodaysData = -1 then
printf(1,"Can't open file \n %s", "TODAYS.TXT")
abort(1)
end if
----------------------------------------------------------------------------------
-- read TODAYS.TXT and append the current record to the appropriate history file
-
-- format of TODAYS.TXT :
----------------------------------------------------------------------------------
--"AD00U","08/22/2000"," 58.92000"," 59.05000"," 58.80000"," 58.92000","
1815"," 18335"
--"AD00Z","08/22/2000"," 59.00000"," 59.05000"," 58.85000"," 58.95000","
32"," 660"
--"AD01H","08/22/2000"," 58.92000"," 59.05000"," 58.80000"," 58.92000","
1815"," 18335"
--"AD01M","08/22/2000"," 58.91000"," 58.95000"," 58.81000"," 58.85000","
0"," 0"
--
------------------------------------------------------
-- Get the name of the history file to be updated --
-- object #1 of TODAYS.TXT --
------------------------------------------------------
-- format of the history file to be appended to is ...
--"08/18/2000"," 59.26000"," 59.28000"," 58.95000"," 59.05000","
1772"," 18068"
--"08/21/2000"," 58.92000"," 59.05000"," 58.80000"," 58.92000","
1815"," 18335"
pos = 1
char = {}
FieldNo = 1
Field = {}
WhichFile = {}
UpdateRecord = {}
FileToUpdate = {}
FilesUpdated = 0
EOF = false
while true do
if FieldNo = 1 then -- accessing TODAYS.TXT
UpdateRecord = get(TodaysData) -- the 1st object, file name
if UpdateRecord[1] = GET_EOF then
EOF = true
exit
end if
if not UpdateRecord[1] = GET_SUCCESS then
puts(1,"Get of Today's Data failed. Aborting...")
exit
end if
else -- FieldNo > 1
UpdateRecord = gets(TodaysData) -- gets() will get rest of record
end if
if atom(UpdateRecord) then
EOF = true
exit
end if
if FieldNo = 1 then
WhichFile = UpdateRecord[2]&".TXT"
WhichFile = "\\CANDLES\\DAILY\\TEST\\"&WhichFile
FileToUpdate = open(WhichFile,"ab") -- open History file for append
if FileToUpdate = -1 then
puts(1,"History File could not be opened...Aborting ...")
puts(1,WhichFile)
wait = wait_key() -- abort(1)
end if
FieldNo += 1 -- get ready for next read (of TodaysData)
else
---------------------------------------------------------------------------------
puts(FileToUpdate,UpdateRecord) -- note -- an ascii 26 is present
-- at beginning of appended record, after first append, but not after
-- subsequent appends of same data.
-- SAMPLE OF UPDATED FILE: first append is the 3rd record shown.
"08/18/2000"," 59.25000"," 59.25000"," 58.98000"," 59.08000","
640"," 648"
"08/21/2000"," 59.00000"," 59.05000"," 58.85000"," 58.95000","
32"," 660"
"08/23/2000"," 56.90000"," 57.35000"," 56.90000"," 57.16000","
529"," 809"
"08/23/2000"," 56.90000"," 57.35000"," 56.90000"," 57.16000","
529"," 809"
"08/23/2000"," 56.90000"," 57.35000"," 56.90000"," 57.16000","
529"," 809"
---------------------------------------------------------------------------------
close(FileToUpdate)
FilesUpdated +=1
FieldNo = 1 -- ready to start at beginning of the next rec in TODAYS.TXT
end if
end while
clear_screen()
printf(1,"Files Updated: %6.0f ",FilesUpdated)
close(TodaysData)
abort(1)
--------------A23D4B41DCE6550F0385724E--
|
Not Categorized, Please Help
|
|