Page 1 of 1

Read a file

Posted: Wed Nov 25, 2015 3:48 pm
by problème
Hello,
I have a directory "dir", in my directory i have two file, myApp.livecode and langue.txt
I want read langue.txt so i do this but it's don't work , i have nothing in my variable texte

Code: Select all

on mouseUp
   open file specialFolderPath ("dir/langue.txt") for read
   read from file ("dir/langue.txt") until EOF
   put it into texte
   close file ("dir/langue.txt") 
   put texte
end mouseUp

Re: Read a file

Posted: Wed Nov 25, 2015 3:52 pm
by Klaus
Bonjopur problème,

you did read the entry about "specialfolderpath" codes in the dictionary, didn't you? 8)
...
put specialfolderpath("resources") & "/langue.txt" into tFile
put url("file:" & tFile) into teste
put texte
...
For smallish files you can use the URL syntax and read the complete file "en bloc"!
Same for writing to file:
...
put fld "your field to save here" into url("file:" & tFile)
...


Best

Klaus

Re: Read a file

Posted: Wed Nov 25, 2015 6:23 pm
by problème
I try to write in the file but i get a error at the line 2 "open file tFile for text " : button "Button": compilation error at line 7 (open: no mode specified), char 19

Code: Select all

on mouseUp
   put specialfolderpath("resources") & "/langue.txt" into tFile
   open file tFile for text 
   write "égegrfg" to file "langue.txt" 
   write "FIN" to file tFile at end 
   close file tFile
end mouseUp

Re: Read a file

Posted: Wed Nov 25, 2015 7:01 pm
by quailcreek
Hi problème,
What platform is your app written for MAC, Win, iOS? I believe you said that the txt file you want to read is in the same directory are you app, right?

Re: Read a file

Posted: Wed Nov 25, 2015 7:07 pm
by problème
Hello,
I want write my app for mac, windows and linux. And yes the text file and my app are the same directory

I found a solution for write in the file:

Code: Select all

on mouseUp
    put specialfolderpath("resources") & "/langue.txt" into tFile
    open file tFile for write
    write "rhghrghrh" to file tFile
    close file ("file:" & tFile)
end mouseUp
thanks for the help

Re: Read a file

Posted: Wed Nov 25, 2015 7:24 pm
by Klaus
This line is not valid syntax: " open file tFile for text"!
"... for write" is the correct syntax, as you have found out.