reg expressions in live code

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
doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

reg expressions in live code

Post by doobox » Thu May 26, 2011 1:47 am

Hi there,

What i am trying to do here is find an icon file in a folder of unknown name.
There will always be only one icon file in this folder and the folder will always be at the same location.
The icon file will always be different though, so i want to use a reg expression to locate the file.

This obviously does not work, but you may be able to see what i am trying to do;

Code: Select all

revCopyFile defaultFolder & "/" & ".+icns" & specialFolderPath("Desktop")
The ".+icns" should reference any icon file in the folder if i can implement it properly.

Maybe there is an easier function to get files from folders by "type" but i cant seem to find a function for that.
Kind Regards
Gary

https://www.doobox.co.uk

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Re: reg expressions in live code

Post by BvG » Thu May 26, 2011 2:20 am

regular expressions are possible with the matchChunk and matchText functions. But I think you want to copy several files, and you'll need to loop over the files anyway, at which point it's easier to do chunk expressions, similar to this:

set the itemdelimiter to "."
repeat for each line theLine in the files
if item -1 of theLine = "icns" then
--do stuff here
end if
end repeat
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

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

Re: reg expressions in live code

Post by Klaus » Thu May 26, 2011 12:05 pm

Hi doobox,

you could also "filter" your list of files:
...
put the files into tFiles
filter tFiles with "*.icns"
## Now only ".icns" files are in the list :D
...


Best

Klaus

doobox
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 284
Joined: Tue May 24, 2011 11:47 pm

Re: reg expressions in live code

Post by doobox » Thu May 26, 2011 1:37 pm

Thank you guys, very helpfull answers.
I am starting to chip my way through the use of chunk expressions in live today.

You know i did this yesterday:

Code: Select all

filter tFiles with ".icns"
So close yet so far away :-)
Kind Regards
Gary

https://www.doobox.co.uk

Post Reply