How to read a external txt file ?

Getting into LiveCode for iOS? Ask your questions here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
sirobchGA0cda
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 47
Joined: Wed Dec 21, 2011 10:42 am
Contact:

How to read a external txt file ?

Post by sirobchGA0cda » Thu May 01, 2014 1:34 pm

Hello,
I try to read a external "txt" file in IOS and put it in a field "read".
I can read the file path but not its contents.
In "Standalone application settings" I put the txt file (folder "documents") in the copy file menu :
Capture d’écran 2014-05-01 à 14.28.19.png

And here is my script in a button :

Code: Select all

on mouseUp
   set the defaultFolder to specialFolderPath("Documents")
   put "file:" & SpecialFolderPath("engine") & french.txt into langFile
   put url ("file:" & langFile) into field "read"
   
end mouseUp
It's possible to help me.
Thanks in advance.
Boris
My application "GeoMaths" is available on Itunes and Google Play !

jmburnod
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 2729
Joined: Sat Dec 22, 2007 5:35 pm
Contact:

Re: How to read a external txt file ?

Post by jmburnod » Thu May 01, 2014 1:38 pm

Salut Boris,

Try this

Code: Select all

on mouseUp
   put  SpecialFolderPath("engine") & "/" & "french.txt" into langFile
   put url ("file:" & langFile) into field "read"
   
end mouseUp
All the best
Jean-Marc
https://alternatic.ch

sirobchGA0cda
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 47
Joined: Wed Dec 21, 2011 10:42 am
Contact:

Re: How to read a external txt file ?

Post by sirobchGA0cda » Thu May 01, 2014 1:54 pm

Salut Jean-Marc,
Thanks for your answer, but the content of the file txt is not put in the field.
Boris
My application "GeoMaths" is available on Itunes and Google Play !

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

Re: How to read a external txt file ?

Post by Klaus » Thu May 01, 2014 2:12 pm

Boris, it is not MANDATORY that you put the content of the file into a field!
A variable will do, too! :D

sirobchGA0cda
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 47
Joined: Wed Dec 21, 2011 10:42 am
Contact:

Re: How to read a external txt file ?

Post by sirobchGA0cda » Thu May 01, 2014 2:58 pm

Thanks Klaus,
Your suggestion made ​​me to try a different code :

Code: Select all

on mouseUp 
   set the defaultFolder to specialFolderPath("Documents")
     open file specialFolderPath("engine") & "/French.txt" for read 
    read from file specialFolderPath("engine") & "/French.txt" until EOF 
    put it into Myvar
put item 1 of line 1 of myvar into field "read"
    close file specialFolderPath("engine") & "/French.txt" 
end mouseUp
and finally it's works.
Boris
My application "GeoMaths" is available on Itunes and Google Play !

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

Re: How to read a external txt file ?

Post by Klaus » Thu May 01, 2014 3:29 pm

Hi Boris,

if you are lazy like me, you can have it much shorter:

Code: Select all

on mouseUp 
    put specialFolderPath("engine") & "/French.txt" into tFile 
    put item 1 of line 1 of url("file:" & tFile) into field "read"
end mouseUp
:D


Best

Klaus

sirobchGA0cda
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 47
Joined: Wed Dec 21, 2011 10:42 am
Contact:

Re: How to read a external txt file ?

Post by sirobchGA0cda » Thu May 01, 2014 4:21 pm

Hi Klaus,
Thank you very much.
I must learn to be lazy. :D
Best
My application "GeoMaths" is available on Itunes and Google Play !

Post Reply