Restored from previous forum. Originally posted by momo.
Hi!
How could my programm know itselfe if a file exists or not???
Is`t there something like DoesFileExist()???
thank's for help!
Don't Look so stupid
I've got no Signature!!
Question about files!!???
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by Berikco.
if filesize(filename$) = -1 ; file does not exist
;do youre stuff
endif
Regards,
Berikco
http://users.pandora.be/berikco/purebasic.htm
if filesize(filename$) = -1 ; file does not exist
;do youre stuff
endif
Regards,
Berikco
http://users.pandora.be/berikco/purebasic.htm
-
BackupUser
- PureBasic Guru

- Posts: 16777133
- Joined: Tue Apr 22, 2003 7:42 pm
Restored from previous forum. Originally posted by LJ.
Or, when opening a file for reading:
File$=""
File$ = OpenFileRequester("", Path$, "PureBasic Source (*.pb)|*.PB|All (*.*)|*.*", 0, #PB_Requester_MultiSelection)
If File$ ""
Repeat
LoadSourceCodeReal(File$)
File$ = NextSelectedFileName()
Until File$ = ""
EndIf
Notice if the handle of the file requester greater than or less than (in other words not equal) "" (nothing) then the file exists.
You can also use Berikco's example of -1 which is nice logic because you can not only use = -1 but > -1 with a savefile requestor to see if the file exists and then prompt to overwrite:
File$ = SaveFileRequester("", Path$, "PureBasic Source (*.pb)|*.PB|All (*.*)|*.*", 0)
If FileSize(File$) > -1
Result = MessageRequester("PureBasic", "This file already exists. Do you want to overwrite it ?", #MB_YESNO | #MB_ICONWARNING)
Or, when opening a file for reading:
File$=""
File$ = OpenFileRequester("", Path$, "PureBasic Source (*.pb)|*.PB|All (*.*)|*.*", 0, #PB_Requester_MultiSelection)
If File$ ""
Repeat
LoadSourceCodeReal(File$)
File$ = NextSelectedFileName()
Until File$ = ""
EndIf
Notice if the handle of the file requester greater than or less than (in other words not equal) "" (nothing) then the file exists.
You can also use Berikco's example of -1 which is nice logic because you can not only use = -1 but > -1 with a savefile requestor to see if the file exists and then prompt to overwrite:
File$ = SaveFileRequester("", Path$, "PureBasic Source (*.pb)|*.PB|All (*.*)|*.*", 0)
If FileSize(File$) > -1
Result = MessageRequester("PureBasic", "This file already exists. Do you want to overwrite it ?", #MB_YESNO | #MB_ICONWARNING)