Opening a file for writing AFTER a file for reading causes problems...

Previous topic - Next topic

MrTAToad

With the following :

Code (glbasic) Select
IF OPENFILE(file1%,"Test.txt",1)
READBYTE file1%,t%
DEBUG ENDOFFILE(file1%)
OPENFILE(file2%,"wibble.txt",0)
DEBUG ENDOFFILE(file1%)
READBYTE file1%,t%
ENDIF


I find that as soon as a file is opened for writing, the file being used for reading is marked has having reached the end of the file (ENDOFFILE returns 1), which is a bit of a problem when it hasn't

Resetting the file position for the file to be read doesn't work either.

I need to be able to write the contents of a file being read to another file and came across this problem - I can't open both at the same time as the filename used for writing is contained in the file being read

Ian Price

I don't think you can read or write to a file without closing any open file first.

Do all your reading, CLOSEFILE, then do your writing.
I came. I saw. I played.

Moru

I'm having the same problem with version 7.181.

I haven't noticed this before since I'm always opening and closing two files at once, the output file has the same name as the inputfile except for the extension. So it's perfectly possible to read and write two files at once, just not open a new file after starting to read another file which has to be a bug?

Kitty Hello

ouch! Please post a complete same to show this. Should be possible if you use 2 different file channels.

MrTAToad

Naughty me!  It looks like I'm using the same file handle...


Moru

Agh, that's what I get for copy-pasting but I didn't have time to make my own test this morning :-)

MrTAToad