QB64.org Forum
Active Forums => QB64 Discussion => Topic started by: SirCrow on December 16, 2018, 09:38:51 am
-
In Linux, I have my prog. delete an existing text file, create a temp one and then rename it to the orig. one's name:
Problem is, when the prog. later tries to write to the renamed file, it always fails.How do I create the text file with write permission? Thanks!
-
When you open a file FOR OUTPUT you already reset its contents, so you don't need to use a temp file if you intend to overwrite the contents of an existing file. Just open Off_Pilots.txt FOR OUTPUT to begin with and write to it as you already do. No previous contents will remain that way.
-
You might need to simply:
OPEN original_file$ FOR OUTPUT AS #2
.
.
.Do stuff
.
.
CLOSE #2
KILL second_file$
RENAME original_file$ AS second_file$
OPEN second_file$ FOR APPEND AS #2
*********
(No need for the SHELL statements, as QB64 can both delete and rename files natively.)
-
You might need to simply:
OPEN original_file$ FOR OUTPUT AS #2
.
.
.Do stuff
.
.
CLOSE #2
KILL second_file$
RENAME original_file$ AS second_file$
OPEN second_file$ FOR APPEND AS #2
*********
(No need for the SHELL statements, as QB64 can both delete and rename files natively.)
Thanks, I appreciate it. But could someone please change KILL to something.....nicer? After all these years?
-
When you open a file FOR OUTPUT you already reset its contents, so you don't need to use a temp file if you intend to overwrite the contents of an existing file. Just open Off_Pilots.txt FOR OUTPUT to begin with and write to it as you already do. No previous contents will remain that way.
As usual, my own code confuses me, but I'm quite sure that I need the temp file at first, as Off_Pilots.txt already exists, and I need to place the end part of it into the temp file to preserve those lines of text. After which, more lines will be appended to it. Make sense?
Thanks, Fellippe, and Happy Anniversary!
Fuller version of my code:
WHILE NOT EOF(1) 'Record the last 25 Pilots removed from duty IF P
> PilCnt
- 25 THEN PRINT #2, P$
'Write the names to temp file