i have a problem. i created a little app and when i click to saveas (in my program) my modified file, open savefilerequest dialog and write a new filename, but not check if the file is exist or not. overwrite it.
this is my save code:
How can i create this: "file.ext already exists. Do you want to replace it?" if i click yes -> overwrite, but if i click no -> put back into savefilereques dialog
Hello. i would use ReadFile() to check if the fileexists. then i would use Messagerequester() for the messages. Yes. No. Cancel. Its all in the manual.
It seems to be a very standard question that pops up every couple of months. I fell in the same trap. It's one of the cases where I'd like an additional keyword such as FileExist()... Yeah, I know I can build one myself, it's for newcomers!
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB)
( The path to enlightenment and the PureBasic Survival Guide right here... )
I think this should go into the "Feature request" section because it's very important.
I bet all of us had this question on time: "How can I find out if the file already exists?"...*searching forum*..."What FileSize()??". Sometimes I even forget this context.
Either include a small FAQ area in the help file that is easy to find for the beginners or add FileExist() - You shouldn't make stepping into PureBasic as hard as possible!
If any of you native English speakers have any suggestions for the above text, please let me know (via PM). Thanks!
Procedure.i FileExists(fileName.s)
If FileSize(fileName) > -1
ProcedureReturn #True
EndIf
EndProcedure
If FileExists(#PB_Compiler_Home + "PureBasic.chm")
Debug "File exists."
Else
Debug "File not found."
EndIf
PureBasic always returns false on zero and null values.
Texas Instruments TI-99/4A Home Computer: the first home computer with a 16bit processor, crammed into an 8bit architecture. Great hardware - Poor design - Wonderful BASIC engine. And it could talk too!Please visit my YouTube Channel
szerda wrote:How can i create this: "file.ext already exists. Do you want to replace it?" if i click yes -> overwrite, but if i click no -> put back into savefilereques dialog
Repeat
ok=#PB_MessageRequester_Yes
f$=SaveFileRequester("Save file","","*.*",0)
If FileSize(f$)>0 ; If size is 0, should be safe to replace. ;)
ok=MessageRequester("Confirm",GetFilePart(f$)+" already exists. Do you want to replace it?",#PB_MessageRequester_YesNo)
EndIf
Until ok=#PB_MessageRequester_Yes
; Now save file here.