[Gambas-user] Path for open file write

Benoit Minisini gambas at ...1...
Sun Jul 6 20:23:46 CEST 2008


On dimanche 06 juillet 2008, Jeff Johnson wrote:
> I know this has probably been replied to many times.
>
> This works
>    hFile = OPEN "wxaprs.ini" FOR INPUT
>
> This works
>    hFile = OPEN "./wxaprs.ini" FOR INPUT
>
>
> This fails with access forbidden
> DIM hFile1 AS File
> hFile1 = OPEN "./wxaprs.ini" FOR OUTPUT CREATE
>
> This fails with access forbidden
> DIM hFile1 AS File
> hFile1 = OPEN "wxaprs.ini" FOR OUTPUT CREATE
>

Relatives paths are paths to files located inside the project, and so are 
read-only.

> This works
> DIM hFile1 AS File
> hFile1 = OPEN "/home/jeffjohnson/aprs/wxaprs.ini" FOR OUTPUT CREATE

...But when you use an absolute path, nothing is checked. But then your code 
does not work once the program is compiled into an executable.

>
> I need to either determine the full working path so I can make it
> hFile1 = OPEN $Path & "wxaprs.ini" FOR OUTPUT CREATE
>
> or the correct way to create a file
>
> Any ideas of where I fell off the trolley?
>

You can't create file inside the project at execution time. You need to store 
your file inside the user home directory.

You can use the Settings class, that creates a settings file like in Windows 
in a standard path inside the user home directory.

Or you can create your own file, as an hidden file (beginning with a dot), or 
as a file stored inside an hidden directory.

Now the standard is defined by freedesktop.org: a configuration file is stored 
in ~/.config/<application>. The Settings class stored its own configuration 
file in ~/.config/gambas[3]/<application>.conf

Regards,

-- 
Benoit Minisini




More information about the User mailing list