Writing to a file
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
Writing to a file
I can't find much about writing to a file.
In particular, can I "write" the contents of a field
in one "go"?
Coding with LC - most fun you can have without taking
your clothes off.
In particular, can I "write" the contents of a field
in one "go"?
Coding with LC - most fun you can have without taking
your clothes off.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing to a file
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Writing to a file
Thanks Richard. I did look through the lessons
but not in the right place.
Next question: to construct a file name that
will be unique.
I thought that "internet time" was
seconds since January 1,1970 so would have
been ideal but can't find anything to confirm.
The LC "internet time" isn't it.
There was also a FoxPro function for "Julian"
date, I think, which would have suited but
can't find that either.
but not in the right place.
Next question: to construct a file name that
will be unique.
I thought that "internet time" was
seconds since January 1,1970 so would have
been ideal but can't find anything to confirm.
The LC "internet time" isn't it.
There was also a FoxPro function for "Julian"
date, I think, which would have suited but
can't find that either.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing to a file
See the UUID function.
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Writing to a file
Ah!
How about "seconds"?
"Returns the number of seconds since the start of the eon."
eon - a very long or indeterminate period of time.
If it's not defined how can you calculate the seconds?
Thank again Richard.
Stand by for more....
Well now I've divided the seconds and it's around
46 years -- just what I thought. From 00.00 on
January 1, 1970.
So perhaps the Dictionary could say this instead of
the rather vague "eon"?
How about "seconds"?
"Returns the number of seconds since the start of the eon."
eon - a very long or indeterminate period of time.
If it's not defined how can you calculate the seconds?
Thank again Richard.
Stand by for more....
Well now I've divided the seconds and it's around
46 years -- just what I thought. From 00.00 on
January 1, 1970.
So perhaps the Dictionary could say this instead of
the rather vague "eon"?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Writing to a file
I've constructed a file name which I called fName
from "Data" and the last four characters of "seconds".
So fName = "Data1385.txt" say.
But if I put
put field Data into URL "file:fName"
I get a file named fName.
Tried a few alternatives without success.
No doubt it's simple - except I don't know how.
Help appreciated.
from "Data" and the last four characters of "seconds".
So fName = "Data1385.txt" say.
But if I put
put field Data into URL "file:fName"
I get a file named fName.
Tried a few alternatives without success.
No doubt it's simple - except I don't know how.
Help appreciated.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing to a file
Anything between quotes is treated as a literal string. To combine a variable name with the string "file:" use the concatenation operator, "&". And to make sure the concatenation is done before the "url" specifier attempts to use it as a single thing, it helps to put that expression in parentheses as shown in the last example of the Lesson I linked to earlier, e.g.:
Code: Select all
put field Data into URL ("file:"&fName)
Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Writing to a file
Well Richard I have to say I'm not in love with this
"URL" method.
A "URL" is something different as far as I'm concerned and
I much prefer the old (simple) method of writing to a file.
Never-the-less after several hours of trying I've got my data files
going to the right place.
I have the path:
set itemDel to "/"
put item 1 to -2 of the filename of this stack into tSFP
Next step: to check that tSFP/DataFiles exists and if not
make it.
Can't find any info on this - I'm suffering from
a severe case of "search fatigue".
Help, as always, much appreciated.
"URL" method.
A "URL" is something different as far as I'm concerned and
I much prefer the old (simple) method of writing to a file.
Never-the-less after several hours of trying I've got my data files
going to the right place.
I have the path:
set itemDel to "/"
put item 1 to -2 of the filename of this stack into tSFP
Next step: to check that tSFP/DataFiles exists and if not
make it.
Can't find any info on this - I'm suffering from
a severe case of "search fatigue".
Help, as always, much appreciated.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing to a file
No worries - you can always use the traditional open/write/close method:RossG wrote:Well Richard I have to say I'm not in love with this
"URL" method.
Code: Select all
set itemDel to "/"
put the filename of this stack into tFile
put "SomeFileName.txt" into last item of tFile
open file tFile for write
if the result is not empty then
answer the result &"(& sysError()&")"
exit to top
end if
write tData to file tFile
close file tFile
That's OK - that's why we're here.Next step: to check that tSFP/DataFiles exists and if not
make it.
Can't find any info on this - I'm suffering from
a severe case of "search fatigue".

Turns out "there is" is an operator which lets you know if there is something. So to see if there is a file at a specified path, you can use:
Code: Select all
if there is a file tFile then
answer "File already exists!"
exit to top
end if
Unfortunately "ain't" is not yet a built-in operator, but a request has been submitted for that:
http://quality.livecode.com/show_bug.cgi?id=3157

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Writing to a file
Richard
I didn't make it clear above that I want to made a directory
(MD anyone?) or as the feminized world would now have it
"create a folder" (and not on my "desktop" which isn't a desk
and even if it was it's not the top).
I didn't make it clear above that I want to made a directory
(MD anyone?) or as the feminized world would now have it
"create a folder" (and not on my "desktop" which isn't a desk
and even if it was it's not the top).
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
Re: Writing to a file
So...some progress made.
Delete folder doesn't work.
Delete folder doesn't work.
- Attachments
-
- Make Directory.zip
- (1.19 KiB) Downloaded 251 times
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 10052
- Joined: Sat Apr 08, 2006 7:05 am
- Contact:
Re: Writing to a file
I don't understand "feminized" in this context, but if you want to create a folder in LiveCode you can use the "create folder" command.RossG wrote:I didn't make it clear above that I want to made a directory
(MD anyone?) or as the feminized world would now have it
"create a folder"
If you really need to use a shell language for that, you can call shell scripts with the "shell" function. Though really, "md"? Please. Everyone knows it's "mkdir".

Richard Gaskin
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
LiveCode development, training, and consulting services: Fourth World Systems
LiveCode Group on Facebook
LiveCode Group on LinkedIn
Re: Writing to a file
It does if you use it properly.Delete folder doesn't work.
newSFP is empty. What do you want to delete?
PowerDebug http://powerdebug.ahsoftware.net
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
PowerTools http://www.ahsoftware.net/PowerTools/PowerTools.irev
Re: Writing to a file
Also note that you can't delete a folder until all its contents are deleted.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
Re: Writing to a file
Wanted to delete the folder just created.mwieder wrote:It does if you use it properly.Delete folder doesn't work.
newSFP is empty. What do you want to delete?
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.