file.READ_WRITE should create file if it doesn't exists #6197
DaneGrinder
started this conversation in
Engine Core
Replies: 2 comments
-
Yeah, creating the file does sound logical. |
Beta Was this translation helpful? Give feedback.
0 replies
This comment was marked as off-topic.
This comment was marked as off-topic.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
The situation:
You want to open a CSV file and append lines to the end of it. The file might already exist or not.
This works as long as the file exists, but if the file has not yet been created the READ_WRITE will not create it and it, therefore, fails (silently)
So, when the file doesn't exist you have to open the file only for writing file.WRITE to create the file. This works fine, but it does not work if the file already exists because the seek_end() is dependent on the file being opened for reading and the result is therefore that the file is always overwritten.
So for now I do an if statement to check if the file exists and if it does I open it file.READ_WRITE and if it doesn't I use file.WRITE to create it. I don't think that should be necessary because file.READ_WRITE could just as easily create the file.
Beta Was this translation helpful? Give feedback.
All reactions