Unable to read a file on my device
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Unable to read a file on my device
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 !!!
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
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)
Merry Christmas (almost)
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Unable to read a file on my device
Hi
As bogs said you may use specialfolderpath("documents")
Try this:
put your file "jcc.txt" in documents folder and try this script
Best regards
Jean-Marc
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
Jean-Marc
https://alternatic.ch
Re: Unable to read a file on my device
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 !
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 !
-
- VIP Livecode Opensource Backer
- Posts: 2718
- Joined: Sat Dec 22, 2007 5:35 pm
- Location: Genève
- Contact:
Re: Unable to read a file on my device
Hi
Try this to create a file "jcc.txt" contains "myTest" in folder documents
Jean-Marc
NO. Documents folder is the folder where your app isI think that the folder « documents » refers to the folder « files » which is inside the app folder
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)
https://alternatic.ch
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Unable to read a file on my device
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.
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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Unable to read a file on my device
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 !
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 !
-
- VIP Livecode Opensource Backer
- Posts: 7237
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: Unable to read a file on my device
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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com