OpenFile(): Add flag #PB_File_NoCreate

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

OpenFile(): Add flag #PB_File_NoCreate

Post 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.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
User avatar
Derren
Enthusiast
Enthusiast
Posts: 313
Joined: Sat Jul 23, 2011 1:13 am
Location: Germany

Re: OpenFile(): Add flag #PB_File_NoCreate

Post 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
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: OpenFile(): Add flag #PB_File_NoCreate

Post by Sicro »

Yes, there are always workarounds, but in my opinion the command should support that natively.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: OpenFile(): Add flag #PB_File_NoCreate

Post 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
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: OpenFile(): Add flag #PB_File_NoCreate

Post 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?
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Little John
Addict
Addict
Posts: 4527
Joined: Thu Jun 07, 2007 3:25 pm
Location: Berlin, Germany

Re: OpenFile(): Add flag #PB_File_NoCreate

Post 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.
User avatar
Sicro
Enthusiast
Enthusiast
Posts: 538
Joined: Wed Jun 25, 2014 5:25 pm
Location: Germany
Contact:

Re: OpenFile(): Add flag #PB_File_NoCreate

Post 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.
Image
Why OpenSource should have a license :: PB-CodeArchiv-Rebirth :: Pleasant-Dark (syntax color scheme) :: RegEx-Engine (compiles RegExes to NFA/DFA)
Manjaro Xfce x64 (Main system) :: Windows 10 Home (VirtualBox) :: Newest PureBasic version
Post Reply