Page 1 of 1
Confusion for placing and accessing Data Folder
Posted: Mon Jul 02, 2012 2:21 pm
by pkmittal
Hi, I am having some problem on Andriod while accessing the data files.
I have data on "TEST Data" folder. To add this data to Andriod App, I went to
standalone applicaton settings --copy files -- add folder and added the TEST Data folder.
TEST Data folder have couple of files. For example 1.jpg
I wrote the following code.
Code: Select all
on mouseUp
set the folder to specialFolderPath("engine")
put empty into tMyImages
put empty into tFolders
put empty into myFolder
put the folders into tFolders
answer tFolders with "OK"
if there is not a folder "TEST Data" then
answer "TEST Data folder missing" with "OK"
end if
if there is not a file "TEST Data/1.jpg" then
answer "1.jpg is missing" with "OK"
end if
end mouseUp
When I run the above code on Andriod Device and also on emulator then tFolder display the list of folders.. and It shows Test Data folder... But the code inside the other if statements are also executed.. meaning it does not find TEST Data folder and also the file 1.jpg inside that folder...
I know that file system on Andriod are case sensitive.. but the folder name is created as used in the code..
Is there different way? Do I need to set something? The way I have added the Test Data folder is incorrect? or there is something wrong in the code....Please help me...
Re: Confusion for placing and accessing Data Folder
Posted: Mon Jul 02, 2012 2:48 pm
by Dixie
pkmittal..
You were nearly there... use this
Code: Select all
set the defaultfolder to specialFolderPath("engine")
be well
Dixie
Re: Confusion for placing and accessing Data Folder
Posted: Mon Jul 02, 2012 3:12 pm
by sturgis
Folder and defaultfolder are synonyms so that should be fine, I think the problem lies with the space in the folder name.
If you change it to this:
Code: Select all
on mouseUp
set the folder to specialFolderPath("engine")
put empty into tMyImages
put empty into tFolders
put empty into myFolder
put the folders into tFolders
answer tFolders with "OK"
if there is not a folder (quote & "TEST Data" & quote) then --puts quotes around the folder name
answer "TEST Data folder missing" with "OK"
end if
if there is not a file (quote & "TEST Data/1.jpg" & quote) then
answer "1.jpg is missing" with "OK"
end if
end mouseUp
I don't know if it will work on android, but "shortfilepath" (check the dictionary) is really handy.
EDIT: Nope doesn't work on android.
Re: Confusion for placing and accessing Data Folder
Posted: Mon Jul 02, 2012 4:07 pm
by pkmittal
Thanks for the prompt responses..on windows it works with out extra quote also.. and folder and defaulfolder is also the same thing.....
I am asking for andriod.. Any idea why it is not workiing on andriod... what one has to change in the above code... is not it something trivial? Is there any any one who has done some programming on android can help?
Re: Confusion for placing and accessing Data Folder
Posted: Mon Jul 02, 2012 5:25 pm
by sturgis
Hmm. Wondering of there is something going on with permissions.
Instead of "if there is a" you can put the folders into a variable as you do and then check to see if the folder name you're looking for is "among the lines of..."
But it seems as if there is more going on. I can't create a folder in specialfolderpath("documents") (error: Can't create that directory) but I SHOULd be able to. So I'm stumped.
Re: Confusion for placing and accessing Data Folder
Posted: Mon Jul 02, 2012 6:34 pm
by Gene
sturgis wrote:Hmm. Wondering of there is something going on with permissions.
Instead of "if there is a" you can put the folders into a variable as you do and then check to see if the folder name you're looking for is "among the lines of..."
But it seems as if there is more going on. I can't create a folder in specialfolderpath("documents") (error: Can't create that directory) but I SHOULd be able to. So I'm stumped.
It's entirely possible that I'm missing the point altogether, as I often do. However, here is a short block of code that should illustrate manipulating folders and files with the specialFolderPath etc. It's a button script that fires off a series of folder and file events:
Code: Select all
on mouseUp
set the defaultFolder to specialfolderpath("Documents")
answer the defaultFolder--shows the path to a folder named "files" rather than "documents," but what the heck
create folder the defaultfolder&slash&"testfolder"--creates a new subfolder of "files"
create folder the defaultfolder&slash&"another_folder"--creates a second folder just to have a list of folders to display
answer the folders--displays subfolders of specialFolderPath("Documents") - aka "files"
set the defaultFolder to specialfolderpath("Documents")&slash&"testfolder"--resets the defaultfolder in preparation to write a file
answer the defaultfolder--this should be "testfolder"
put "Hello from Testfolder" into temp
put temp into URL "file:testfile.txt"
answer the files--lists the files within the new default folder, "testfolder"
answer URL "file:testfile.txt"--Contents of the text file can be read. Q.E.D.
end mouseUp
I only tested this on Windows and on my Android phone, not the simulator. The simulator is a tool of the devil

(just kidding, I think).
I hope this helps - Gene
Re: Confusion for placing and accessing Data Folder
Posted: Tue Jul 03, 2012 5:03 am
by pkmittal
Any Expert can tell me what is wrong with the code below? The engine folder shows the TEST Data folder.. but when we do if there is not a folder "TEST Data" is executed... meaning it does not find the TEST Data folder. and when we do the following
set the folder to specialFolderPath("engine") & slash & "TEST Data"
then it is able to find the files... please help.. let me know if my question is not clear enough.. please read the initial query in the quote below.. thanks
pradeep
pkmittal wrote:Hi, I am having some problem on Andriod while accessing the data files.
I have data on "TEST Data" folder. To add this data to Andriod App, I went to
standalone applicaton settings --copy files -- add folder and added the TEST Data folder.
TEST Data folder have couple of files. For example 1.jpg
I wrote the following code.
Code: Select all
on mouseUp
set the folder to specialFolderPath("engine")
put empty into tMyImages
put empty into tFolders
put empty into myFolder
put the folders into tFolders
answer tFolders with "OK"
if there is not a folder "TEST Data" then
answer "TEST Data folder missing" with "OK"
end if
if there is not a file "TEST Data/1.jpg" then
answer "1.jpg is missing" with "OK"
end if
end mouseUp
When I run the above code on Andriod Device and also on emulator then tFolder display the list of folders.. and It shows Test Data folder... But the code inside the other if statements are also executed.. meaning it does not find TEST Data folder and also the file 1.jpg inside that folder...
I know that file system on Andriod are case sensitive.. but the folder name is created as used in the code..
Is there different way? Do I need to set something? The way I have added the Test Data folder is incorrect? or there is something wrong in the code....Please help me...
Re: Confusion for placing and accessing Data Folder
Posted: Tue Jul 03, 2012 4:41 pm
by Klaus
Hi Pradeep,
pkmittal wrote:set the folder to specialFolderPath("engine") & slash & "TEST Data"
there is nothing wrong with this line!
You should use more parenthesis however:
set the folder to (specialFolderPath("engine") & "/TEST Data")
Sometimes the engine will only evalutae the first part of the string (before the first &), therefore parens
should be used whenever possible and it makes sense!
But as I tried to point out in anohter thread, using relative filenames after setting the defaultfolder
does obviously NOT work as exspected on mobile devices, so try to always use absolute filenames!
...
put (specialfolderpath("engine") & "/TEST Data") into tFolderInQuestion
answer (there is a folder tFolderInQuestion)
put (specialfolderpath("engine") & "/TEST Data/1.jpg") into tFileInQuestion
answer (there is a file tFileInQuestion)
## should display TRUE if you added the files and folder via the "Copy files" tab in the standalonebuilder.
...
So your desired "copy files/folders from engine to docs folder" routine should look like this:
Code: Select all
command do_the_copy
## 1. create abolute pathnames!
put (specialfolderpath("engine") & "/TEST Data") into tEngineFolderTEST
put (specialfolderpath("documents") & "/TEST Data") into tDocsFolderTEST
## 2. Check for folder and create folder if necessary
if there is not a folder tDocsFolderTEST then
create folder tDocsFolderTEST
end if
## 3. Now get the list of files in that folder:
set the folder to tEngineFolderTEST
put the files into tFiles2Copy
## 4. Now copy all the files to the docs folder in a repeat loop:
repeat with i = 1 to the num of lines of tFiles2Copy
## 5. Again: Create absolute filenames, thsi will ALWAYS work! :-)
put (tEngineFolderTEST & "/" & line i of tFiles2Copy) into tSourceFile
put (tDocsFolderTEST & "/" & line i of tFiles2Copy) into tTargetFile
## 6. Check if files are already present, optional
if there is NOT a file tTargetFile then
put url("binfile:" & tSourceFile) into url("binfle:" & tTargetFile)
end if
end repeat
end do_the_copy
Do so for every folder/file you need to copy to the docs folder to be able to modify/edit them.
Best
Klaus
Re: Confusion for placing and accessing Data Folder
Posted: Tue Jul 03, 2012 4:55 pm
by pkmittal
Thanks.. I will try this code.. but it wil keep the files at 2 places.. 1) engline and 2) documents?
Is there not a way to directly have the files in documents folder when we install the app.
Re: Confusion for placing and accessing Data Folder
Posted: Tue Jul 03, 2012 5:30 pm
by Klaus
pkmittal wrote:Thanks.. I will try this code.. but it wil keep the files at 2 places.. 1) engline and 2) documents?
Yes.
pkmittal wrote: Is there not a way to directly have the files in documents folder when we install the app.
You decide, you are the developer
No, since the app is "only" copied to the device, there is no install routine of any kind at all!
Therefore you need to take care of this when the app starts (the first time) e.g. with my script.
Please get used to it!
Best
Klaus