FolderItem nil on Linux but OK on Windows

This code works fin on Windows, but when it executes the last line in Linux, f is nil. Before that it is /Home/EZMeter.

[quote] dim f As new FolderItem
#if TargetWin32 or TargetMacOS
f = SpecialFolder.SharedDocuments
#else
f = SpecialFolder.Home
#endif
f = f.Child(“EZMeter”)
if not f.Exists Then f.CreateAsFolder
f = f.Child(“EZConfig.sqlite”)[/quote]

I am new to Linux and not at all comfortable with it yet. I have set the permissions for the EZMeter directory and the sqlite file to 777 after I copied the files, I copied them from Windows to a flash drive then to the /Home/EZMeter directory.

Rather than re-using “f” over and over like that, you might want to use a separate variable for each distinct FolderItem so you can better determine what is Nil:

[code]Dim homeLocation As FolderItem
homeLocation = SpecialFolder.Home

Dim ezMeterLocation As FolderItem
ezMeterLocation = homeLocation.Child(“EZMeter”)

If ezMeterLocation <> Nil Then
If Not ezMeterLocation.Exists Then ezMeterLocation.CreateAsFolder

Dim sqlFile As FolderItem
sqlFile = ezMeterLocation.Child(“EZConfig.sqlite”)
End If[/code]

if not f.Exists Then f.CreateAsFolder
f = f.Child(“EZConfig.sqlite”)

you realize if the 1st line executes and creates a new folder, that the second line WILL FAIL every time… as you JUST created an EMPTY folder

Never use 777 for data. Max 666 please.
Octal 7 could enable a attack vector of execution, if people could write your file contents by any chance.
By rule, set 7 only where it’s really necessary.
To be true probably it should be 664 or 660 (unknown can read or unknown can nothing).
666 lets “not owners” read and write, but not execute that file as a binary or script, as a 667 would.
666 should be chosen only when the accessing member is not configured correctly as member of the permitted group, and you need them to write that file. It does not compromise your server, but could compromise your data.

This is true in a first run application. This may well be what the OP wants, it is how I test if my application is running for the first time. Some pseudo code:

[code]dim myDBFile as FolderItem = GetTheFolderItemAsDescribedEarlier

if not myDBFile.Exists then
CreateAndConnectToNewDatabase
else
OpenAndConnectToExistingDatabase
End If[/code]

Hope this helps.

Simon.