Working with files

Blitz3D Forums/Blitz3D Programming/Working with files

vivaigiochi(Posted 2011) [#1]
I work with several types of text file.
Only work well but if i don't close the program the file aren't write on disk after closefile(...). There is some flush command? if i want see the result of my operation i must close the program...


Midimaster(Posted 2011) [#2]
please send a minimal sample code, where you can see this behavior on your machine. Then I will have a look on mine.


vivaigiochi(Posted 2011) [#3]
excuse me and thanks for your help.
I can't post code (for time reasons..) the problem is essentially what i say...
yes often the file after closefile isn't on disk or it's incomplete. i say about text file and i work with a progran that manipulate many text file.
So if i want create a file i must ask to the user of close the main program to read the file just created? ...


tyoud(Posted 2011) [#4]
Are you saying that you are writing to a file, via random access or something, but that it doesn't actually commit the changes to the file until you close it with closefile()?


Midimaster(Posted 2011) [#5]
if the file is not visible after you thought it has to be...but the file is visible after shutdown the program, this has to do with a never processed CloseFile() command. At the end of program, B3D closes all open streams. (...all files YOU missed to close...). This means your code never did it!

Or the Closefile()-command is not corresponding to the stream any more....Perhaps, because the stream ID has changed?

for test purposes try to define your stream-variable GLOBAL. try to comment all OpenFile(), Writexxx() and CloseFile() commands with a DEBUGLOG and see in the debugger, whether the sequence of commands was as you expected. You should see a sequence of opening, writing and closing with always the same ID:

GLOBAL Stream
....
Function blabla()
      ....
     Stream=OpenFile
     DEBUGLOG "Open Stream ID=" + Stream
     ....
End Function

Function WriteSomething_blabla()
     .....
     WriteLine Stream, "Hello"
     DEBUGLOG "Write to Stream ID=" + Stream + "  Line=" + "Hello"
     ....
     WriteByte Stream, Value
     DEBUGLOG "Write to Stream ID=" + Stream + "  Byte=" + Value
     ....
End Function

Function Final_blabla()
     CloseFile Stream
     DEBUGLOG "Close Stream ID=" + Stream
End Function


The main reason, why I sometimes got this behavior, was an EXIt or RETURN command before the Closefile(). Search in your code for lines like this:
Function Save()
     Stream=Openfile("...")
     For i=0 to Max
          WriteLine Stream , Text[i]
          If Text[i]="" Then RETURN
     Next
     CloseFile Stream
End Function




There is a big difference between "file not on disk" and "incomplete". If the file is incomplete, it could be caused by a value in the file, which the text editor could not understand, f.e. a Byte with the value of Zero causes the text editor the continue reading...

We need more information about what you are writing on the disk (text, Bytes, ...) and you really should send some code example...for time reasons :-)

Last edited 2011


Bobysait(Posted 2011) [#6]
there is also some other answers :

1/ Use 'F5' key on your browser to actually see modifications in the folder.
It may help ... or not.

2/ "read only" access on folders attributes ?


vivaigiochi(Posted 2011) [#7]
yes i'm sure not modify the stream variable (see code in this page :-) ) during elaboration of data. But yes there are some exit call...i will try to closefile first of those


_PJ_(Posted 2011) [#8]
A possible reason for missing CloseFile() is if for some reason, the file has been Opened or Read twice but only closed once.
Beware of multiple Opening!