Page 1 of 1

Newbie again

Posted: Sat Feb 09, 2019 2:24 pm
by dhobbs
All I want to do is open a text file and display it in a text field, modify it, then save it again. I can use the Answer command, but that gives me the path. How do I get the contents of the file? I've used Live code a long time ago (RunRev era), but the new dictionary is perplexing to me, and I can't remember how I loaded, searched, edited, and saved the text file. Can someone point me in the right direction?

Re: Newbie again

Posted: Sat Feb 09, 2019 2:36 pm
by Klaus
Hi dhobbs,

Code: Select all

## Load file into field:
...
answer file "Select text file:"
put IT into tFile

## User CANCELled
if the result = "cancel" then
   exit to top
end if

## Load file into field:
put url("file:" & tFile) into fld "your field here..."
...

Code: Select all

## Save field content to file:
...
put specialfolderpath("desktop") & "/your file.txt" into tFile
put fld "your field here..." into url("file:" & tFile)
...
Best

Klaus

Re: Newbie again

Posted: Sat Feb 09, 2019 2:43 pm
by bogs

Code: Select all

## Save field content to file:
...
put specialfolderpath("desktop") & "/your file.txt" into tFile
put fld "your field here..." into url("file:" & tFile)
...
Just to prevent some possible confusion, Klaus is using a direct save to the desktop in the above code, if you wanted to save it elsewhere, you'd have to use 'answer folder', if you wanted to save it back to where it came from, you could make tFile a script local variable.

You could also use a combination of the above in an 'if/then' branch off.

Re: Newbie again

Posted: Sat Feb 09, 2019 2:48 pm
by dhobbs
Perfect, thanks.
I totally forgot about the url keyword. Not particularly intuitive.
Appreciate it...