More Newbie Q - File Access

Getting there… I am having issues with file access. I do this:

f = New FolderItem("/home/pi/Pipes_User_Library", FolderItem.PathModes.NativePath)

f then is not Nil, but it says it does not exist. The client says he is sure the path exists and that it is 777. Is there something wrong with my call?

Hi Garth,

I am trying to run a simple program on my Raspberry Pi with Xojo 2020 r1.1 and I am getting the following error:

An exception of class IOException was not handled. The application must shut down. Exception Error Number: 2

I made a text file called Hello and in the file I added a row of text called Hello World

Here is my code:

Sub Action() Handles Action
  Var FString as String
  FString = "/home/pi/Pipes_User_Library"
  Var f as FolderItem
  f = New FolderItem(FString, FolderItem.PathModes.Shell)
  f = f.Parent.Child("Hello")
  
  If f <> Nil Then
    Var MyText as TextInputStream
    MyText = TextInputStream.Open(f)
    Label2.Text = MyText.ReadAll.ToText
    MyText.Close
  Else
    MessageDialog.Show("f <> Nil error")
  End If
End Sub

I am unable to use FolderItem.PathModes.NativePath as it won’t compile.

Not sure what to say, but something is wrong. I tried some other folderitem examples and am getting errors.

Why would my project compile when I use FolderItem.PathModes.NativePath, but it won’t compile with your project? That seems confusing to me.

Thats a good question, and I don’t know the answer. I am on Windows 10 with Xojo 2020 r1.1?

The correct thing to be using is: FolderItem.PathModes.Native. You should consult the docs more:

https://documentation.xojo.com/api/files/folderitem.html.PathModes

This line of code is from my app:

outputf = new FolderItem (ofn, FolderItem.PathModes.Native)

and it is in running code.

Hi Tim,

Thanks for the comment. Yep, I did consult the docs and saw that the term Native is used. I don’t know if there is a discrepancy on the website or if there is an issue with 2020 r1,1?

What is your guess?

I started my development computer and changed the command back to Native and it compiled. Wierd.

Now the program just provides this error on the Raspberry Pi.

RPi2020r11ErrorMessage

Hi @Eugene_Dakin

Maybe you want to try this in order to get more clues about if you can reach that file after all (i.e. creating a valid instance from the “Hello” child on the Parent directory for the Folderitem pointed by the provided path, right permissions, etc.):

Does the “Hello” file exists and it has some kind of file extension not included?

Sub Action() Handles Action
  Var FString as String = "/home/pi/Pipes_User_Library"
  Var f as FolderItem
  Try
    f = New FolderItem(FString, FolderItem.PathModes.Native)
    f = f.Parent.Child("Hello")
  
    Var MyText as TextInputStream = TextInputStream.Open(f)
    Label2.Value = MyText.ReadAll
    MyText.Close
  Catch e as IOException
    MessageBox e.Message
  End Try

End Sub

You have a wrong char in the pathname, type it over manuly in a string or constant and parse that value…

Native is definitely right and NativePath wrong and it doesn’t compile. My guess is you had it right but somehow copied it wrongly into your OP, when you were talking about f not being Nil but f.exists being false. Looking here at my code, testing with NativePath, and looking at the doc I see no inconsistency.

Edit - oh wait it wasn’t your OP, sorry :rofl:

2 Likes

Sorry @Garth_Hjelte, I didn’t think that this would be so difficult.

I changed the example to your code @Javier_Menendez, and received an empty error (here is the screen grab):

When I press the button, a window opens that contains no text. Below is the zipped file to download the project and it also contains the Hello file.

Pi Program and Hello File

@DerkJ I tried it manually, and I am getting an error. Thanks for the suggestion!

Thanks @TimStreater, the term Native is correct :slight_smile:

Nobody really answered my question, but your discussion was educational anyway. My client got it figured out, I really was doing the right thing. I just thought there was some secret stuff regarding ARM.

1 Like