Ok, I see I can use File_Open with Append for the mode and then File_LinePrint and then File_Close. Should do the trick for now.
Hi Guys, is there a File Append type command I am not seeing.
That is, I have a text based file, I just want to append content to it at the end WithOUT having to open it, load it up and then add the new content and then save it out again.
Thanks for any info.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Ok, I see I can use File_Open with Append for the mode and then File_LinePrint and then File_Close. Should do the trick for now.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
I can't get it to append. I tried seeking to the eof and still no luck.
[code=thinbasic]
local s as string
local n as long
s = Str$(planetColorX) + "," + Str$(planetColorY) + "," + Str$(planetColorZ) + "," + Str$(planetX) + "," + Str$(planetY)_
+ "," + BackgroundBMP + $crlf
if (n = FILE_OPEN("LikeSavedSettings.txt", "Append")) then
FILE_Seek(n, FILE_EOF) 'Just added this and still couldn't get it to work, thought it might need it
FILE_LinePrint(n, s)
FILE_CLOSE(n)
end if[/code]
Thanks in advance.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Ken,
the code
[code=thinbasic]
if (n = FILE_OPEN("LikeSavedSettings.txt", "Append")) then
[/code]
is not returning the file id but comparing the value of n (that is zero at that point) with the fileid returned by file_open.
So you are not storing any file id anywhere.
Also file_open with "APPEND" mode automatically set the file cursor at the end of the file and if the file does not exists, it is created.
So, do it simple, step by step. Open the file and get file id. Test file id and if ok, write what you need and close.
[code=thinbasic]
USES "file"
local s as string
local FileID as long
S="123" '--- Write here whatever
FileID = FILE_OPEN(app_soucepath & "LikeSavedSettings.txt", "APPEND")
if FileID then
FILE_LinePrint(FileID, s)
FILE_CLOSE(FileID)
end if
[/code]
Another info: file_seek will not work for files open in append mode.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks Eros for the very clear explanation and example!!!
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Ken,
in thinBasic an assignement directive starts with a variable.
So,
[code=thinbasic]
n = FILE_OPEN("LikeSavedSettings.txt", "Append")
[/code]
is an assignment directive, while
[code=thinbasic]
if (n = FILE_OPEN("LikeSavedSettings.txt", "Append")) then
[/code]
is a comparison directive. N will not given a value but the value of N is compared with the value returned by File_Open but never assigned to N.
Other languages have = or := to assign and == to compare. Or even other mix.
In thinBasic we want it simple and easy to understand so most of the time it is better to just write different sentence: one for assignement and one for comparing.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
I agree, it does make it so much easier to follow what is happening. Look at the mistake I made otherwise, trying to combine it as I did. Thanks again Eros.
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Ken,
I've added FILE_Append function.
Should be more easy to use.
Ciao
Eros
www.thinbasic.com | www.thinbasic.com/community/ | help.thinbasic.com
Windows 10 Pro for Workstations 64bit - 32 GB - Intel(R) Xeon(R) W-10855M CPU @ 2.80GHz - NVIDIA Quadro RTX 3000
Thanks Eros, I love being spoiled with such goodies, couldn't be any easier!!
Acer Notebook: Win 10 Home 64 Bit, Core i7-4702MQ @ 2.2Ghz, 12 GB RAM, nVidia GTX 760M and Intel HD 4600
Raspberry Pi 3: Raspbian OS use for Home Samba Server and Test HTTP Server
Bookmarks