5 Replies Latest reply: Nov 16, 2013 1:01 AM by Aminabot
MAMEBase Level 1 Level 1 (0 points)
I'm having some problems with Automator, and I'm hoping it's just a simple step I'm missing.

I have a list (text file) of a group of files I wish to remove from a folder (about 650 or so files, from a folder of about 8000). I have been able to get Automator to read the text file, and show me the result.

(Ask for Finder Items (Files & Folders), Combine Text Files (Text), Filter Paragraphs [Return Paragraphs That Are Not Empty] (text))

This results in showing me my list of files I wish to remove.

I don't quite get how to pass this list on to the Finder to tell it to select these files, and move them to the trash.

Any assistance would be appreciated.

Power Mac G5, Mac OS X (10.5.7)
  • red_menace Level 6 Level 6 (14,785 points)
    The Move Finder Items to Trash action should do what you want, if you are providing the complete file path. How are your files defined in the text file (name only, POSIX path, etc)?
  • MAMEBase Level 1 Level 1 (0 points)
    Thanks for responding!

    The text file in question is a list of file names with extensions, separated by returns.

    I realize I may be going about this the wrong way, and am perfectly willing to start from scratch.

    What I'm trying to accomplish is to move a group of files (based on the file names) from a specific folder to the trash (allowing me to examine them one last time before deleting them).

    I have a text file (generated by another application) that lists the files I want to purge.

    Ideally, I want Automator to select the files (in a specified folder), based on the list I provide, and move said files to the trash.

    I'll be happy to provide you with any additional details you may require, and thanks again for your help!
  • red_menace Level 6 Level 6 (14,785 points)
    Since your text file just has the names, an action is needed to build the complete file path. Most of Apple's text and file actions don't use variables, but a Run AppleScript action can be used to fill in the blank. Give this workflow a try (I haven't tested it with a large number of files, so I don't know how slow it will be):

    1) Ask for Finder Items {Files} -- choose the text file
    2) Combine Text FIles
    3) Filter Paragraphs {Return paragraphs that are not empty}
    4) Run AppleScript -- paste the following script:
    <pre style="
    font-family: Monaco, 'Courier New', Courier, monospace;
    font-size: 10px;
    font-weight: normal;
    margin: 0px;
    padding: 5px;
    border: 1px solid #000000;
    width: 720px;
    color: #000000;
    background-color: #FFEE80;
    overflow: auto;"
    title="this text can be pasted into an Automator 'Run AppleScript' action">
    on run {input, parameters} -- build file paths from a list of names

    set output to {}
    set SkippedItems to {}

    set TheFolder to (choose folder with prompt "Select the folder containing the files:") as text

    repeat with AnItem in the input
    try
    set AnItem to (TheFolder & AnItem)
    get AnItem as alias -- test
    set the end of the output to the result
    on error
    set the end of SkippedItems to AnItem
    end try
    end repeat

    if SkippedItems is not {} then
    display alert "Error with AppleScript action" message ((count SkippedItems) as text) & " items were skipped (file not found)"
    end if

    return output
    end run</pre>
    5) Move Finder Items to Trash
  • MAMEBase Level 1 Level 1 (0 points)
    Ah!

    I suspected that an AppleScript function would need to be involved.

    Sadly, I know less about AppleScript than I do Automator.

    Let me give it a try, and I'll let you know the result...

    Wait
    Time Passes...


    Success!

    The files were purged successfully, and it only took it a minute or less!

    Rhanks again!
  • Aminabot Level 1 Level 1 (0 points)

    Hey red_menace,

     

    You once helped me with a similar issue by writing me almost the exact same Applescript.

     

    It's worked like a charm for a long time... until Mavericks.

     

    It basically comes back with all of the items skipped. Any thoughts on why?

     

    Thanks for taking a look!