Feel my pain . . .

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

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

Feel my pain . . .

Post by richmond62 » Sat Apr 12, 2025 5:15 pm

I have a folder containing a large number of text files . . .

They have names like this "Richmond's socks.txt"

Now I want to import ALL of them at once into a stack and bung them into the custom properties of an object: and I want each custom property to be named after the document, a bit like this:
-
Screenshot 2025-04-12 at 19.14.01.png

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

Re: Feel my pain . . .

Post by Klaus » Sat Apr 12, 2025 5:16 pm

And what is the painful part?

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

Re: Feel my pain . . .

Post by dunbarx » Sat Apr 12, 2025 5:21 pm

Richmond.

I am with Klaus. What, apart from reading each text file and a few lines of LC in a handler is the problem?

Or did it have something to do with:
Now I want to import ALL of them at once into a stack
the "all at once" part.

Craig

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

Re: Feel my pain . . .

Post by richmond62 » Sat Apr 12, 2025 5:48 pm

Indeed: with about 300 text files I would end up with serious W*nk*r's cramp doing that manually.

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

Re: Feel my pain . . .

Post by Klaus » Sat Apr 12, 2025 6:01 pm

Ever heard of a repeat loop? 8)

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

Re: Feel my pain . . .

Post by richmond62 » Sat Apr 12, 2025 6:19 pm

"a repeat loop" ?

I seem to remember something about something called that in BBC BASIC in about 1977. 8)

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

Re: Feel my pain . . .

Post by Klaus » Sat Apr 12, 2025 6:27 pm

So do you have a serious question or are you just bored and want to waste a bit of our time, too?

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

Re: Feel my pain . . .

Post by richmond62 » Sat Apr 12, 2025 6:30 pm

The serious question boils down to 2 things:

1. How to use a repeat loop to import multiple text files.

2. Set those up as custom properties of an object where each custom property is given the name of the originating text document.
So do you have a serious question or are you just bored and want to waste a bit of our time, too?
Sarcasm on your part will only result in sarcasm on my part. 8)

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

Re: Feel my pain . . .

Post by Klaus » Sat Apr 12, 2025 6:41 pm

Code: Select all

on mouseUp 
   answer folder "Where are the bloody files?"
   put it into tFolder
   put files(tFolder) into tFiles
   ## remove DOT files
   filter tFiles without ".*"
   repeat for each line tLine in tFiles
      set the tLine of this stack to url("file:" & tFolder & "/" & tFile)
   end repeat
end mouseUp
Do you know how to access a custom property with SPACES in its name like "Richmond's Socks"?
And I was not sarcastic but actually a tad annoyed! 8)

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

Re: Feel my pain . . .

Post by Klaus » Sat Apr 12, 2025 7:12 pm

Before you ask, you will need to use a variable for this:

Code: Select all

...
put "Richmond's Socks" into tCPName
put the tCPName of this stack into fld "display"
...

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

Re: Feel my pain . . .

Post by richmond62 » Sat Apr 12, 2025 7:36 pm

I would have thought that was fairly obvious as otherwise 'Richmond's' and 'Socks' would be treated as 2 different words.
-
Screenshot 2025-04-12 at 21.37.34.png
-
And I was not sarcastic but actually a tad annoyed!
I don't see why: my 'problem' had got nothing to do with a repeat loop, BUT how to set the custom property's name to the name of a text document, and how, then to put the contents of that document into the custom property.

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

Re: Feel my pain . . .

Post by Klaus » Sat Apr 12, 2025 9:00 pm

Hi Richmond,
richmond62 wrote:
Sat Apr 12, 2025 7:36 pm
I would have thought that was fairly obvious as otherwise 'Richmond's' and 'Socks' would be treated as 2 different words.
good one! :D
You have to admit that some "obvious" (more or less basic) LC solutions/scripting are/is not really obvious to you despite your +20 years of XTalk experience.
richmond62 wrote:
Sat Apr 12, 2025 7:36 pm
And I was not sarcastic but actually a tad annoyed!
I don't see why: my 'problem' had got nothing to do with a repeat loop, BUT how to set the custom property's name to the name of a text document, and how, then to put the contents of that document into the custom property.
Why?
I had asked what the "painful" part was, since that was not obvious to me, and instead of answering directly you wrote:
Indeed: with about 300 text files I would end up with serious W*nk*r's cramp doing that manually.
I always like to help, even if I have little time, so that's what I call "wasting my time".

Best

Klaus

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

Re: Feel my pain . . .

Post by dunbarx » Sat Apr 12, 2025 10:50 pm

Richmond.

Klaus, and I, were both trying to understand what you needed.

You know this.

Don't let this go south.

Craig

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

Re: Feel my pain . . .

Post by richmond62 » Mon Apr 14, 2025 10:00 am

HOWEVER . . .

Code: Select all

on mouseUp 
   answer folder "Where are the bloody files?"
   put it into tFolder
   put files(tFolder) into tFiles
   ## remove DOT files
   filter tFiles without ".*"
   repeat for each line tLine in tFiles
      set the tLine of this stack to url("file:" & tFolder & "/" & tFile)
   end repeat
end mouseUp
Does NOT appear to put the contents of the files into the customProperties. :(

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

Re: Feel my pain . . .

Post by Klaus » Mon Apr 14, 2025 10:05 am

Oops, sorry, made in a hurry:

Code: Select all

...
 repeat for each line tLine in tFiles
     ###  set the tLine of this stack to url("file:" & tFolder & "/" & tFile)
     set the tLine of this stack to url("file:" & tFolder & "/" & tLine)
   end repeat
...

Post Reply