I’m trying to check if a File Exists (INI)
If not.. it should create the File with the proper strings.
How do I that?
I tried..
s_text = “[DATABASE]” + “~r~n” + &
"Server=" + "~r~n" + & "UserId=" + "~r~n" + & "Password=" + "~r~n" + & "DB=" + "~r~n"FileWrite(config.ini”, s_text)
but it says invalid argument to file
For testing if the file exist, there is the
FileExists( filename )that returns a boolean. That function only needs a file name to perform the check.On the opposite,
FileWrite()needs to work on an opened file. It is given a “file number” that is generated by a call toFileOpen()(and that file number should also be given toFileClose()at the end of the process).Why not looking at the PowerBuilder documentation? There is a sample for that : from the PB IDE, press F1, look at the
FileWrite PowerScript functionsection, then press the Example button. (Surprisingly, the example does not mentionFileClose()but you DO need to call it ;o)Don’t forget to check for invalid file numbers (for example if the file name does not exist, or if the file is already in use).
EDIT: as the OP clarified in the comments that he would like to be able to call
SetProfileString()on a non-existing ini file (that cannot create a new ini file), here is an example of new ini file creation :