excluding items from a list of file names

I’m getting a list of file names from a folder and I have a list of names to exclude from the file names list. What’s the best way to do that? Here’s what I have so far…

set thePath to path to desktop folder
tell application "System Events" to set allList to name of every item of thePath whose (name is not ".DS_Store" and name is not ".localized")

The above works but the problem is I need the list of names to exclude to be in a list, because the list items will change. So I tried this but it doesn’t work.

set excludedList to {".DS_Store", ".localized"}
set thePath to path to desktop folder
tell application "System Events" to set allList to name of every item of thePath whose name is not in excludedList

I can loop through the file names list, and check each one against the exclude list, and build a new list of those names… but that’s not very fast. Is there a better way?


set thePath to path to desktop folder
tell application "Finder" to set allList to name of every item of thePath

:wink:

I’m not sure what that is StefanK, it doesn’t exclude anything. What do you mean?

Oh I get it, it will exclude those items, but I need to see other invisible items that may be in the folder, so using the Finder doesn’t work because it doesn’t show any invisible items.

I was just kidding a bit ;),

the Finder excludes all invisible files, System Events does not

Yes, I figured that but at first you had me confused! :stuck_out_tongue:

Why doesn’t the “whose name is not in…” work. If I search the forums that is the answer that is given… so when did it stop working and why did is stop working? I certainly don’t want to loop through the file names list if I don’t have to.

This seems to work:

set excludedList to {"Dev"}
set thePath to path to home folder
tell application "Finder" to set allList to name of every item of thePath whose name is not in excludedList

That does work! Unfortunately I can’t use the Finder as I explained. But why does that work and not the same thing with system events? Very strange…