Page 1 of 1

OpenFile(): Add flag #PB_File_NoCreate

Posted: Sat Aug 31, 2019 3:39 pm
by Sicro
PB help wrote:Opens a file for reading/writing or creates a new file if it does not exist.
It would be good if the command had a flag that could disable the creation of a new file.
If the file does not exist then #False should be returned.

Re: OpenFile(): Add flag #PB_File_NoCreate

Posted: Sat Aug 31, 2019 3:53 pm
by Derren
Use

Code: Select all

If FileSize(path) > -1 ;only open the file if it already exists
    OpenFile(fileID, path) 
Endif
If there's a flag, PB needs to check if the file exists, anyway, so it's probably not even faster to have it as a flag, versus what you can already do with a single If

Re: OpenFile(): Add flag #PB_File_NoCreate

Posted: Sat Aug 31, 2019 4:00 pm
by Sicro
Yes, there are always workarounds, but in my opinion the command should support that natively.

Re: OpenFile(): Add flag #PB_File_NoCreate

Posted: Sat Aug 31, 2019 4:17 pm
by Little John
Sicro wrote:If the file does not exist then #False should be returned.
E.g. the name #PB_File_Existing would be more intuitive then. :-)

File existing?
Yes --> #True
No --> #False

Re: OpenFile(): Add flag #PB_File_NoCreate

Posted: Sat Aug 31, 2019 10:20 pm
by Sicro
@Little John:
You mean it should work the other way around: Instead of disabling the creation of the file with the flag #PB_File_NoCreate, there should be a flag #PB_File_Existing that enables the creation?

Re: OpenFile(): Add flag #PB_File_NoCreate

Posted: Sat Aug 31, 2019 11:39 pm
by Little John
Sicro wrote:@Little John:
You mean it should work the other way around: Instead of disabling the creation of the file with the flag #PB_File_NoCreate, there should be a flag #PB_File_Existing that enables the creation?
No, I don't mean that. That would be a different feature request. :-)

I mean: If Fred will implement what you are asking for, then the new flag shold be named e.g. #PB_File_Existing (short for #PB_Open_Only_An_Already_Existing_File) rather than #PB_File_NoCreate.

Re: OpenFile(): Add flag #PB_File_NoCreate

Posted: Sun Sep 01, 2019 11:14 am
by Sicro
Little John wrote:#PB_File_Existing (short for #PB_Open_Only_An_Already_Existing_File) rather than #PB_File_NoCreate
Okay, I'm fine with that, too.