Apple Event: May 7th at 7 am PT

Looks like no one’s replied in a while. To start the conversation again, simply ask a new question.

Moving files to the Trash with Automator

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)

Posted on Aug 3, 2009 7:47 PM

Reply
5 replies

Aug 4, 2009 7:23 PM in response to red_menace

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!

Aug 4, 2009 9:24 PM in response to MAMEBase

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

Moving files to the Trash with Automator

Welcome to Apple Support Community
A forum where Apple customers help each other with their products. Get started with your Apple ID.