Page 1 of 1

reg expressions in live code

Posted: Thu May 26, 2011 1:47 am
by doobox
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.

Re: reg expressions in live code

Posted: Thu May 26, 2011 2:20 am
by BvG
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

Re: reg expressions in live code

Posted: Thu May 26, 2011 12:05 pm
by Klaus
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

Re: reg expressions in live code

Posted: Thu May 26, 2011 1:37 pm
by doobox
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 :-)