My first test in Linux

Hi group, I’m trying to read a text file in Xojo. I state that everything works with Windows, but now I’m trying the program in Linux.
The code I use is as follows:

FileDiTesto = GetFolderItem(“”)
#If DebugBuild=True then
FileDiTesto = FileDiTesto.Parent
PathDelProgramma=FileDiTesto.NativePath + “database/impostazioni.txt”
FileDiTesto = FileDiTesto.Child(“database/Impostazioni.txt”)

messagebox " PathDelProgramma :" + PathDelProgramma 'PATH IS OK

FileDiTesto = New FolderItem(PathDelprogramma, FolderItem.PathModes.Native)


The complete path appears in the messagebox, but it gives me an error when opening it, saying that the file does not exist, even if in the path it is perfect as a path.
Where am I wrong?

Instead of using things like this “database/impostazioni.txt” in your code it is recommended that you use:


That will work on any platform no matter what the delimiter is (\ or /). These methods also return a FolderItem so there is no need to use this sort of thing:

New FolderItem(PathDelprogramma, FolderItem.PathModes.Native)
FileDiTesto = GetFolderItem(“”)
#If DebugBuild=True then
   FileDiTesto = FileDiTesto.Parent
   FileDiTesto =FileDiTesto.NativePath.child(“database").child("impostazioni.txt”)
   FileDiTesto = FileDiTesto.Child(“database").Child("Impostazioni.txt”)

One warning, however, if there is any chance that a folder may or may not exist, for example “database” then the above code would cause a nil object exception. To avoid this you should test each folder before you use methods of it.

FileDiTesto = FileDiTesto.Parent.child("database")
if FileDiTesto<>nil and FileDiTesto.exists then
   FileDiTesto = FileDiTesto.child("impostazioni.txt")
   if FileDiTesto<>nil and FileDiTest.exists then
      // do what you need with the file
   end if
end if

One more thing. You cannot use a path with child.

// Is not valid, only a file / folder that exists in the parent folder is allowed.
FileDiTesto = FileDiTesto.child(“database/impostazioni.txt”)

Ok thanks IAN, I will take your suggestions into account.
I’ll try to modify the code, let’s see what happens.
Obviously, not being a professional programmer, many concepts are not easy for me to understand, but I will always try to study them to the best of my ability.

Good. Now you may change the way you share code. Here’s the code you shared earlier, using
to get ot styled as code:

FileDiTesto = GetFolderItem("")
#If DebugBuild=True Then
FileDiTesto = FileDiTesto.Parent
PathDelProgramma=FileDiTesto.NativePath + "database/impostazioni.txt"
FileDiTesto = FileDiTesto.Child("database/Impostazioni.txt")
PathDelProgramma = f.Nativepath

MessageBox "PathDelProgramma :" + PathDelProgramma 'PATH IS OK

FileDiTesto = New FolderItem(PathDelprogramma, FolderItem.PathModes.Native)

NB: in the styled code above, the quotes are the correct one; a Copy / Paste of this code will not generate errers because of that.

Also: GetFolderItem is deprecated. A simple look in the documentation will show you that:

messagebox " PathDelProgramma :" + PathDelProgramma

If you write this line as below, you will get a better (nice) result:
MessageBox " PathDelProgramma :" + EndOfLine + EndOfLine + PathDelProgramma

Do you know that the Xojo IDE can autocomplete instructions (code) for you ?
Try messageB + Tab and you will get MessageBox

Very personal comment: I do not know what difference there can be between Linux and Windows for the code above (nor MacOS, if that matter).
But: testing your code thru the developement of the project is a good idea.

A simple curiosity about the “deprecated” question. The commands work even if they are “deprecated” in some cases, should I replace each command every time Xojo is updated?

And one more question … I am now with great effort, I am building a program. In 5 years, will my program work the same or will the “deprecated” commands give errors? In short, do I always have to stay there to update the old commands?

Do you know there is a Documentation web site ?

In short: deprecated means “one of these days, this will be removed”. So, use it at your own perils. (better use current code).

Another example. In 2006 there appeared a book called “Beginning REALBasic From Novice to Professional” by Jerry Lee Ford.
I get an eye on it yesterday, and copy / paste a piece of code using the then “REALSQLdatabase”…
That code still works !

But I will not release an application using so old code.

You should look up deprecated in the documentation - that will answer all your questions.

1 Like

Yes sure, of course.