title: Applescript: if file contains any of names move to specific folder
body: <p>I'm trying to make a script that will do this:</p>
  
  <p>There will be a .txt file with a list of names, one per paragraph, like this:</p>
  
  <pre><code>name1
  name2
  name3
  name4
  name5
  </code></pre>
  
  <p>There also will be a folder with lots of files in it.
  I want the script to look at every file in that folder, and in any of the names listed in .txt file are contained in the file name, then move that file to a specific folder. If the file name does not contain one of the names from the list, then move that file to a different folder. </p>
  
  <p>Example:</p>
  
  <pre><code>- There are "name1", "name2" and "name3" in the .txt file.
  - There are "000name2000.jpg", "000name7000.jpg" and "000name3000.jpg" in the folder. 
  - "000name2000.jpg" contains "name2" in it so it should be moved to folder1.
  - "000name3000.jpg" should be moved to folder1 as well. 
  - And "000name7000.jpg" should be moved to folder2.
  </code></pre>
  
  <p>I want it to be so because this list with names will be very long and I want script to be as small as possible.</p>
  
  <p>This is how my script looks like now:</p>
  
  <pre><code>property source_folder : alias "path:to:source_folder"
  property tattoos_folder : alias "path:to:first_folder"
  property models_folder : alias "path:to:second_folder"
  property text_file : alias "path:to:text_file.txt"
  
  process_folder(source_folder)
  
  on process_folder(this_folder)
    set these_items to list folder this_folder without invisibles
    set container_name to name of (info for this_folder)
    repeat with i from 1 to the count of these_items
    set this_item to alias ((this_folder as Unicode text) &amp; (item i of these_items))
    if folder of (info for this_item) is true then
    process_folder(this_item)
    else
    process_item(this_item, container_name, i)
    end if
    end repeat
  end process_folder
  
  on process_item(this_item, c, i)
    if i &lt; 10 then
    set i to "000" &amp; i
    else if (i &lt; 100) and (i &gt; 9) then
    set i to "00" &amp; i
    else if (i &lt; 1000) and (i &gt; 99) then
    set i to "0" &amp; i
    end if
  
    set r to (random number from 0 to 9999)
    if r &lt; 10 then
    set r to "000" &amp; r
    else if (r &lt; 100) and (r &gt; 9) then
    set r to "00" &amp; r
    else if (r &lt; 1000) and (r &gt; 99) then
    set r to "0" &amp; r
    end if
  
    tell application "System Events"
    -- get file extension so not overwritten
    set e to name extension of this_item
    set new_name to "" &amp; r &amp; "" &amp; c &amp; "" &amp; i &amp; "." &amp; e
    set name of this_item to new_name
    move this_item to first_folder      -- THIS IS WHERE THIS NEW PART OF CODE SHOULD BE
    end if                              -- IF NAME IS (meets name from .txt file) THEN MOVE TO first_folder,
    end tell                            -- IF ANOTHER THEN MOVE TO second_folder
  end process_item
  
  display notification "All images were processed." with title "New" sound name "Glass.aiff"
  tell me to quit
  </code></pre>