Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


try this | 16 comments | Create New Account
Click here to return to the 'try this' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
try this
Authored by: Graff on Oct 31, '03 12:07:49AM

Heh, whups. I thought you meant that you couldn't get my modifications to work. I see now that you were just saying that you had problems with writing something similar to what I used.

The key difference between these this statement:

if the name of aFile contains {".jpg"} then

and this one:

if the name extension of aFile is in {"jpg", "gif", "png"} then

are the keywords contains and is in.

When you use the keyword contains with a list it wants to match ALL of the items in the list (a logical AND), so if you did:

if the name of aFile contains {".jpg", ".gif", ".png"} then

The only thing that would match would be a file named "myfile.jpg.gif.png", or any file with all of those somewhere in it.

The keyword is in gives a match if one or more of the items in the list match (a logical OR). Since you are looking for a .jpg OR a .png OR a .gif and so on, this is what you want to use.

I also used name extension since that strips off all the file name except for the extension (even the dot). You have to do this because is in looks for exactly that item in the list. If I didn't do this then an item named "myfile.jpg" wouldn't be found in the list {"jpg, "png", "gif"}. However just "jpg" would be found in that list.

For a file like myfile.jpg.zip it gets more complicated. Basically then I would use the text item delimiters statement to chunk out all the stuff seperated by dots and then compare to those. You can read about how to do that in this MacCentral AppleScript Primer article, but it's probably not worth doing.



[ Reply to This | # ]