Page 1 of 1

How to filter text in field?

Posted: Sun Jan 14, 2007 2:31 pm
by BIX
I wanted to filter some text in field and show only files with image extensions.

I've done it this way

Code: Select all

filter field someField with "*jpg"
but it only shows .jpg files.

I want to know is it possible to filter the field with more extensions, like .jpg, .png... I've tried to find it out but i couldn't?

Posted: Sun Jan 14, 2007 2:51 pm
by xApple
The "filter" command can have its limitations...
You seam to be looking for a more complex script...

I've writen something that should do what you want.. tell me what you think about it.

Code: Select all

  set the itemDelimiter to "."
  put "jpg" & return & "jpeg" & return & "png" into myFormatList
  put "1" into x
  repeat
    put last item of line x of field "someField" into myFormatExtension
    put "no" into passTest
    repeat with y = 1 to the number of lines of myFormatList
      if myFormatExtension is line y of myFormatList then put "yes" into passTest
    end repeat
    if passTest is "no" then
      delete line x of field "someField"
    else
      add 1 to x
    end if
    if (x > the number of lines of field "someField") or (field "someField" is empty) then exit repeat
  end repeat

Posted: Sun Jan 14, 2007 3:05 pm
by BIX
it works fine, thanks

Posted: Tue Jan 23, 2007 8:09 pm
by Mark Smith
This is simpler, and will be a lot faster, if the list of files is very long:

put fld "fileList" into tFList
set the itemDelimiter to "."
repeat for each line L in tFList
if item -1 of L is among the items of "jpg,jpeg,png,gif" then
put L & cr after tFilteredList
end if
end repeat
put char 1 to -2 of tFilteredList into fld "fileList"

best,

Mark