Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!
open file (fld "txtTwo") for read
answer the result = "can't open that file"
read from file (field "txtTwo") at -101 for 400
answer the result = "file is not open for read
Haven't had any problems opening and reading disk files.
would like to read the file into memory and then be able to read it as if it were a disk file:
read from file x at 1 until "some String"
etc
Any suggestions?
If you read the whole file into memory (i.e. into a variable) then the read commands no longer work. Use offset or other text functions instead. But reading from files is very fast, so usually there's no need to put the whole thing into memory unless you need to change something or manipulate the content in some way.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
on mouseup
doReadFileUntilString "LiveCode is great" --you have this text. in your file
end mouseup
on doReadFileUntilString pString
answer file "0pen"
put it into tFile
open file tFile for read
read from file tFile at 1 until pString
close file tFile
put it
end doReadFileUntilString
dntknwjck wrote: Tue Aug 27, 2019 8:19 pm
would like to read the file into memory and then be able to read it as if it were a disk file:
read from file x at 1 until "some String"
etc
Do you want to read the file into memory, or traverse it on disk?
Richard Gaskin LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
I have two things in mind:
1- The dictionary shows an example of reading from a field as if the field was a file. I think tat is an interesting concept and have tried to make it work, but have not been successful with that.
2- I am trying to determine the best way to repeatedly access various information from a file. Speed and ease of access are the concerning factors. Based on the information below it seems that just accessing the file repeatedly is the best solution.
jacque wrote: Wed Aug 28, 2019 6:13 pm
by jacque » Wed Aug 28, 2019 11:13 am
If you read the whole file into memory (i.e. into a variable) then the read commands no longer work. Use offset or other text functions instead. But reading from files is very fast, so usually there's no need to put the whole thing into memory unless you need to change something or manipulate the content in some way.
The example I used was just copied from the dictionary reading from the end of the file. With what I am doing I would read from the begging of the file not the end.
Are you referring to this example in the "Read" entry?
read from file (field "Datafile") at -100 for charsToRead
That isn't very clear, but it will only work if the content of the field is the path to the file on disk. It doesn't mean you can use the "read" command to treat the field content as though it were a file. I can see why that example would be confusing; they should have done it this way:
read from file (field "filePath") at -100 for charsToRead
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
Thanks for the insight about "read from file (field "Datafile") at -100 for charsToRead" in the dictionary.
Not sure I would ever have figured that out, but it does make sense.
Your example should be put in the dictionary as it is much clearer than what it currently there.