Read/Write file

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
jeanvouillon
Posts: 21
Joined: Sat Jan 15, 2011 6:40 pm

Read/Write file

Post by jeanvouillon » Sat Jan 15, 2011 6:50 pm

Hi,
I have tried to read/write a txt file, following the tutorial (http://lessons.runrev.com/spaces/lesson ... he-iPhone-).
My stack works fine in the 4.2 iPad simulator, but when I deploy it on a real 4.2.1 iPad, it doesn't work anymore: when I try to get the information from the file, I just get its filename instead...
Did I missed something obvious? Any suggestions?
Thanks.

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read/Write file

Post by Klaus » Sat Jan 15, 2011 7:31 pm

Hi Jean,

could you please post the relevant script(s)?

best

Klaus

jeanvouillon
Posts: 21
Joined: Sat Jan 15, 2011 6:40 pm

Re: Read/Write file

Post by jeanvouillon » Sat Jan 15, 2011 9:06 pm

Hi Klaus,

I kept it simple:

A 'save' button:
on mouseUp
set the defaultFolder to specialFolderPath("documents/")
put URL ("file:notes.txt") into field "notes"
end mouseUp

A 'open' button:
on mouseUp
set the defaultFolder to specialFolderPath("documents/")
put field "notes" into URL ("file:notes.txt")
end mouseUp

In the simulator it's working fine, but on the iPad "notes.txt" is displayed in the field when the open button is clicked...

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read/Write file

Post by Klaus » Sat Jan 15, 2011 9:49 pm

Hi Jean,
jeanvouillon wrote:...but on the iPad "notes.txt" is displayed in the field when the open button is clicked...
IS displayed or IS NOT displayed?
If its displayed, what is your problem? 8)

You could check the result after saving and loading of the file.
"the result" should be empty after successful writing/reading of the file.
...
put fld "notes" int URL...
answer the result
...

Same after loading.


Best

Klaus

jeanvouillon
Posts: 21
Joined: Sat Jan 15, 2011 6:40 pm

Re: Read/Write file

Post by jeanvouillon » Sat Jan 15, 2011 10:02 pm

Hi Klaus,
Sorry for the confusion.
When I wrote that "notes.txt" was displayed, it's mean that the name of the file was displayed, instead of its content...

I'm going to check the result,
Thanks for the advice

jeanvouillon
Posts: 21
Joined: Sat Jan 15, 2011 6:40 pm

Re: Read/Write file

Post by jeanvouillon » Sat Jan 15, 2011 10:06 pm

Hi again,
The result is "Can't open file" when I try to write or read the file...

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read/Write file

Post by Klaus » Sat Jan 15, 2011 10:36 pm

Hi Jean,

ah, sounds like a permission problem.
Maybe the Defaultfolder did not get set?

Try this to avoiid setting the defaultfolder:
...
put URL ("file:" & specialFolderPath("documents") & "/notes.txt") into field "notes"
...
put field "notes" into URL("file:" & specialFolderPath("documents") & "/notes.txt")
...

Best

Klaus

jeanvouillon
Posts: 21
Joined: Sat Jan 15, 2011 6:40 pm

Re: Read/Write file

Post by jeanvouillon » Sat Jan 15, 2011 10:55 pm

Great! :D
It's working!
Thanks Klaus for the solution and your fast answer!

Klaus
Posts: 14182
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Read/Write file

Post by Klaus » Sun Jan 16, 2011 12:38 am

Bonsoir Jean,

we memorize:
Setting "the defaultfolder" does not work as exspected on iOS (yet) :D

Bon nuit, mon ami!


Best

Klaus

Post Reply