Page 1 of 1
Unable to read a file on my device
Posted: Sat Dec 23, 2017 8:50 am
by jcc75
Hello.
I can't read a file on my device. I read many topics around here, I tried a lot of solutions, but nothing works for me.
My file "jcc.txt" is in the folder "/Tests".
I tried "file:/Tests/jcc.txt", "file:/mnt/Tests/jcc.txt", "file:/storage/Tests/jcc.txt" (I even tried "file:/storage/emulator/0/...").
Nothing works. I'm really desperate !!!
I know that the paths are not the same into different devices. Mine is a Honor. How can I know the right path to use ?
I need some help, please.
Thanks.
Reading this forum, I also learned that the "answer file", and the other file dialog boxes, don't work on Android. I spent some time studying the LiveCode lessons about "working with files", and I was amazed that the sample scripts didn't work !!! Now I know why !
It would have been nice to specify it in the lessons
Merry Xmas everybody !!!
Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 9:16 am
by bogs
What I believe you want to look for in the dictionary is 'SpecialFolderPath', I don't do android, but I know Klaus has posted about this a few times.
Merry Christmas (almost)

Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 12:03 pm
by jmburnod
Hi
As bogs said you may use specialfolderpath("documents")
Try this:
put your file "jcc.txt" in documents folder and try this script
Code: Select all
put specialfolderpath("documents") & "/" & "jcc.txt" into tPath
put url ("file:" & tPath
Best regards
Jean-Marc
Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 1:27 pm
by jcc75
Thank you for your answers.
But this doesn’t work

With the jmburnod’s script, tPath returns : /data/user/0/com.yourcompany.yourapp/files/jcc.txt
I think that the folder « documents » refers to the folder « files » which is inside the app folder, and so is not allowed.
The only « data » folder that I can see is inside the Android folder. So I can’t use a relative path to go to the root.
I didn’t think that reading a file with Android was so difficult !
Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 2:42 pm
by jmburnod
Hi
I think that the folder « documents » refers to the folder « files » which is inside the app folder
NO. Documents folder is the folder where your app is
Try this to create a file "jcc.txt" contains "myTest" in folder documents
Code: Select all
put specialfolderpath("documents") & "/" & "jcc.txt" into tPath
put "myTest" into url ("file:" & tPath)
Jean-Marc
Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 6:34 pm
by jacque
Android uses a "virtual" file path configuration, and you will not be able to see the file on disk. Don't worry about trying to find it in a file manager, just trust it will be there.
Because these are virtual file paths which exist only in RAM, let LC manage them internally and use specialFolderPath to access them. LC will know where they are. If you want to check, you can use "there is a file..." to see if it's there. Jean-Marc gave an example of how to access a file using specialFolderPath.
Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 7:25 pm
by jcc75
Thank you for your explanations.
I understand now how this works.
I can read my file with the specialfolderpath "engine".
I would have preferred to put my file in some other folder, as an external file, but no matter. I use the "Copy Files" in the Standalone Application Settings, and it works. It's the most important for me.
Thank you again
And Merry Christmas !
Re: Unable to read a file on my device
Posted: Sat Dec 23, 2017 8:43 pm
by jacque
You can copy the file from specialFolderPath("resources"), which is where "engine" actually points to, to the folder specialFolderPath("external documents"). That will place it in the visible area of the file system. But you'll need to figure out what the destination file path should be in the external system, and probably will need to create a folder there to hold it.