Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
Mag
- VIP Livecode Opensource Backer

- Posts: 802
- Joined: Fri Nov 16, 2012 10:51 pm
Post
by Mag » Fri Oct 07, 2016 6:44 pm
Hi all,
I would like to use in my app some .wav files that I put in a folder near the stack from which then I create a standalone. All work fine when I run the stack in the IDE but when in standalone the list of files I create with this statement "put the files into soundListFiles" is empty.
I also tried to include the folder and all the files contained in the folder in the "Copy Files" section of the Standalone Application Settings but without luck.
Maybe I missed something or I'm doing the things wrong?
Code: Select all
if the environment is "development" then -- let's start from the location of the stack
put the effective filename of this stack into myPath
set the itemDelimiter to slash
put "mySounds/" into last item of myPath
set the defaultFolder to myPath
else -- standalone
set the defaultFolder to "mySounds"
end if
put the files into soundListFiles
answer soundListFiles -- when in standalone this list is empty

-
Klaus
- Posts: 14208
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Fri Oct 07, 2016 7:01 pm
Hi Mag,
Mag wrote:...
I also tried to include the folder and all the files contained in the folder in the "Copy Files" section of the Standalone Application Settings but without luck.
...
but this is the way to go!
Use -> specialfolderpath("resources") then, which will ALSO work in the IDE!
If you are using LC 8.x then you don't have to mess around with -> the defaultfolder!
This will replace the complete script you posted and will work in the IDE and standalone:
...
put files(specialfolderpath("resources") & "/mySounds") into soundListFiles
answer soundListFiles
...
Best
Klaus
-
Mag
- VIP Livecode Opensource Backer

- Posts: 802
- Joined: Fri Nov 16, 2012 10:51 pm
Post
by Mag » Sun Oct 09, 2016 3:03 pm
Thank you Klaus!
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Sun Nov 13, 2016 11:57 am
I am trying to store some files in other folders under the Android OS.
I think if one could update the data in a particular folder, when an update to that file would be easy to do.
I have actually achieved this by setting the defaultFolder to the Documents folder in the file manger so that I won't have reload the application.
The problem is, each device has a different file structure, ie on my phone the Documents folder is under /storage/emulated/0/documents, and on a nexus 7 the documents folder is under /nexus 7 /documents.
I understand that the package in Android is stored in a Virtual folder for security purposes and a data file can be placed in the package under the Make a standalone, but the idea is to be able to update a data file by just uploading an updated file to the device, say to whatever folder that you may want to store that data.
I guess if there was a way to identify what the device is that you are using, I could a pick list of file structure options based on the device.
ANy ideas out there?
Clarence Martin
chipsm@themartinz.com
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sun Nov 13, 2016 6:51 pm
LC knows where the documents folder is on any device. All you need is specialFolderPath("documents").
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Sun Nov 13, 2016 8:24 pm
But this folder is on the virtual folder that Android creates when the project is loaded?
Clarence Martin
chipsm@themartinz.com
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sun Nov 13, 2016 10:01 pm
It's in the app's sandbox. The data is preserved when a new app version is installed, and deleted when the user deletes the app from the device. Android OS stores the sandbox data in a (usually) inaccessible location unless the device is rooted. It isn't something you need to manage, the OS does it.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Sun Nov 13, 2016 11:01 pm
Thanks, jacque. I seem to be having problems finding my *.txt file that I have loaded in the standalone settings.
So, if I want to update my text file in the sandbox, this is something that can't done without uploading a new app?
Sorry about all of the questions.
Clarence Martin
chipsm@themartinz.com
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Sun Nov 13, 2016 11:18 pm
You dont need a new app. Just download the text file and overwrite the one in specialFolderPath("documents") and you're done. It's the same as any other folder, the only reason it's "special" is because the location can vary. But LC knows where it is, so it's easiest to let LC figure it out.
Note that on first install you will need to copy the text file you ship with the app from specialFolderPath("resources") to specialFolderPath("documents").
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Sun Nov 13, 2016 11:52 pm
Thanks.
Imust have head full bricks now. I need some time to absorb this.This should be simple ....But....
I know what you are stating but for some reason ,I can't seem to make this work.
I will be posting a little later. Maybe I'll include a little test stack that I have.
Clarence Martin
chipsm@themartinz.com
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Mon Nov 14, 2016 2:33 am
Hi jacque,
this is an update or follow up from my previous post. When I made this demo stack to test where mobile files were and how to update them, I copied some code from a previous application. It seems as though there was some leftover information that was somehow in memory that was not allowing me to find the real defaultFolder information.
So, sometime tomorrow, I will attempt to try coding this stuff again.
This was so frustrating but now I am sure that your suggestions will work.
I will keep you updated and thanks again.
Clarence Martin
chipsm@themartinz.com
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Mon Nov 14, 2016 3:25 am
It's probably easier than you expect, so you overlooked it. Whatever you put in the Copy Files pane of the standalone builder gets put into a folder named "resources" in the standalone. The folder structure you indicated in Copy Files is maintained. When your standalone needs to access a file, it looks in "resources" for it. So, say your text file is loose in the Copy Files pane. In the app, it will be in:
specialFolderPath("resources") & "/mytext.txt"
If the text file is inside another folder, which is in Copy Files, then it will be in:
specialFolderPath("resources") & "myFolder/mytext.txt"
It stays there when you run the app and you can read from it, but you can't write to it or update it because standalones can't be altered. So in this case you need to copy that file to a folder which has write permissions, which is the "documents" folder. On launch your script should check to see if "documents" has that text file and if not, copy it there:
put url ("file:" & specialFolderPath("resources") & "/mytext.txt") into url ("file:" & specialFolderPath("documents") & "/mytext.txt")
Whenever you want to update the text file, you download it or get the data some other way, put it into a variable, and do this:
put myNewData into url ("file:" & specialFolderPath("documents") & "/mytext.txt")
It's just a file path and you can treat it like any other. If you prefer to open file/write to file/close file instead of using the url syntax, you can do that too using the same file paths.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Mon Nov 14, 2016 6:04 am
Again, thanks for the information.
This explains it very clearly.
I love it when things work and when I know how they work.
Iam saving this post in my OneNote notes page as a reference.
Clarence Martin
chipsm@themartinz.com
-
chipsm
- VIP Livecode Opensource Backer

- Posts: 244
- Joined: Wed May 11, 2011 7:50 pm
Post
by chipsm » Mon Nov 14, 2016 5:37 pm
Hi jacque,
Thanks again.....
Everything works just fine.
As usual for me, I was overthinking things and I was able to eliminate some "If statement code" by using your suggestions.
The beauty of this method -- using specialFolderPath -- is that I don't need to manually detect whether the app is running in a mobile vs. a desktop environment.
REALLY COOL!
Clarence Martin
chipsm@themartinz.com
-
jacque
- VIP Livecode Opensource Backer

- Posts: 7393
- Joined: Sat Apr 08, 2006 8:31 pm
-
Contact:
Post
by jacque » Mon Nov 14, 2016 6:10 pm
Yeah, it's pretty cool. The other special folders are equally useful.
One particularly cool thing about the resources folder is that it works during development too as long as the files and folders that you will include in the Copy Files pane are in the same folder as the mainstack. There's no need to branch the code for the current environment.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com