Exporting text files . . . again

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!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Exporting text files . . . again

Post by richmond62 » Wed Apr 23, 2025 5:23 pm

So: I have a field that contains my data (let's call it "myGUFF") and another field that contains the title I wish to call my exported text file (let's call it "myHEAD"), and I also want to date stamp the text file.

So, if field "myHEAD" contains "Stuffed Aubergines", on exporting from that field I SHOULD end up with a file called:

Stuffed Aubergines 4/23/25.txt

BUT I cannot seem to manage that:

Code: Select all

on mouseUp
     put the fld "myGUFF" into GUFF
     put GUFF into url("file:" & fld "myHEAD" && the date & ".txt")
     get the longFilePath of it
     set the itemDelimiter to slash
     set the defaultFolder to item 1 to -2 of the longFilePath of it
end mouseUp
OBVIOUSLY I am going wrong somewhere . . .

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

Re: Exporting text files . . . again

Post by Klaus » Wed Apr 23, 2025 6:11 pm

Hi richmond,

Mac or Windows?

Code: Select all

put the fld "myGUFF" into GUFF
Leave out the THE!

Code: Select all

put GUFF into url("file:" & fld "myHEAD" && the date & ".txt")
1. Unless you have set the defaultfolder to something different than "default",
this will be INSIDE of the Mac application package of LC.
We may not have write permission there.
2. "the date" will contain SLASHES, and these are "forbidden" characters for filenames on a Mac.

Code: Select all

get the longFilePath of it
What is IT right here?
Probably not what you might exspect or even empty.

Code: Select all

set the defaultFolder to item 1 to -2 of the longFilePath of it
See above...

Best

Klaus

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10315
Joined: Wed May 06, 2009 2:28 pm

Re: Exporting text files . . . again

Post by dunbarx » Wed Apr 23, 2025 6:29 pm

Richmond.

Like Klaus, I have little context. But this:
set the defaultFolder to item 1 to -2 of the longFilePath of it
Looks like you are trying to access a custom property of the variable "it". Variables do not have custom properties only objects like controls, cards and stacks.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10315
Joined: Wed May 06, 2009 2:28 pm

Re: Exporting text files . . . again

Post by dunbarx » Wed Apr 23, 2025 6:31 pm

Richmond.

Does "it" contain an object reference? If so, you may be able to work it that way, but will likely need to use a "do" construction, to force another level of evaluation. Otherwise LC will not understand your intent. Let me know if you need an example of that sort of shenanigans.

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Exporting text files . . . again

Post by richmond62 » Wed Apr 23, 2025 6:48 pm

"the date" will contain SLASHES, and these are "forbidden" characters for filenames on a Mac.
Ouch.

This makes me feel a bit mental:
-
Screenshot 2025-04-23 at 21.00.09.png

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

Re: Exporting text files . . . again

Post by Klaus » Wed Apr 23, 2025 7:07 pm

Save some typing:

Code: Select all

...
put the date into XDATE
replace "/" with "$" in XDATE
...
And what about IT?

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Exporting text files . . . again

Post by richmond62 » Wed Apr 23, 2025 7:17 pm

Code: Select all

on mouseup
   set itemDel to "/"
   set the defaultfolder to item 1 to -2 of (the effective fileName of this stack)
   put the date into XDATE
   set the itemDelimiter to "/"
   put item 1 of XDATE into X1
   put item 2 of XDATE into X2
   put item 3 of XDATE into X3
   put X1 & "$" & X2 & "$" & X3 into XXX
   put fld "myGUFF" into GUFF
   put GUFF into url("file:" & fld "myHEAD" && XXX & ".txt")
end mouseup
works a charm! 8)

Thank you very much for your help.

Mind you, I wonder if there might not be something more sensible than a dollar sign that MacOS will not object to.

OK, OK: changed "$" to "-". :D

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

Re: Exporting text files . . . again

Post by Klaus » Wed Apr 23, 2025 7:23 pm

No need to set "the defaultfolder"!
The folder where "this stack" resides -> specialfolderpath("resources")

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 10094
Joined: Fri Feb 19, 2010 10:17 am

Re: Exporting text files . . . again

Post by richmond62 » Thu Apr 24, 2025 9:47 am

Save some typing:
Thank you, I will. 8)

Post Reply