Removing an Item from one List based on Another List

Say I have a list:

set myList to {"John Doe/Stuff01", "John Malcom/stuff", "John Doe/Stuff02", "Jane Doe/stuffage", "Jane Doe/wierdness"}

And I have a second list:

set myExclusions to {"John Doe", "Jane Doe"}

I want to be able to take everything in myExclusions as a sort of “contains” and remove them from myList, which would yield:

{"John Malcom/stuff"}

So basically use the contents of one list in a sort of “if a list record in this other list contains this keyword, remove that list entry.”

I can’t even begin to wrap my head around how to manage that.

Hi Kevin,

quick&dirty, it assumes always the slash behind the name in myList

set myList to {"John Doe/Stuff01", "John Malcom/stuff", "John Doe/Stuff02", "Jane Doe/stuffage", "Jane Doe/wierdness"}
set myExclusions to {"John Doe", "Jane Doe"}

set resultList to {}
repeat with j in myList
	if text 1 thru ((offset of "/" in j) - 1) of j is not in myExclusions then set end of resultList to contents of j
end repeat

Hmmm…getting a “1 thru 0” error on the text command. I’m guessing it’s because some of my strings start with the “/” character, because they are directory entries, I hadn’t considered a solution coming back that would be so situation-specific, my bad.

Say I have a directory path like this in the list:

“/Volume/Path/Category/Name/File.jpg”

Then I want to get rid of every entry like this that has “Name” in it. So to elaborate on my first case example:

List #1:
{“/Volume/Path/Category/John Doe/File1.jpg”, “/Volume/Path/Category/Jane Doe/File1.jpg”,“/Volume/Path/Category/John Doe/File2.jpg”,“/Volume/Path/Category/Bob Doe/File1.jpg”}

List #2:
{“Jane Doe”, “Bob Doe”}

If I asked to remove every entry of List #1 that contains something in List #2, I’d get:

{“/Volume/Path/Category/John Doe/File1.jpg”}

I had hoped it would be generic enough a handler without these details, my apologies. I am dealing with path names from a list, such as a shell “find” command or a items dragged on a drag-n-drop script. Idea is I will look for one list, but may have to pare it back before running it through another handler.

Again, sorry for the lack of details impeding progress.

the better the information, the better the quality of the responses :wink:

next try:


set myList to {"/Volume/Path/Category/John Doe/File1.jpg", "/Volume/Path/Category/Jane Doe/File1.jpg", "/Volume/Path/Category/John Doe/File2.jpg", "/Volume/Path/Category/Bob Doe/File1.jpg"}
set myExclusions to {"Jane Doe", "Bob Doe"}
set resultList to {}
set {TID, text item delimiters} to {text item delimiters, "/"}
repeat with j in myList
	if text item -2 of j is not in myExclusions then set end of resultList to contents of j
end repeat
set text item delimiters to TID