Copying and moving files with Automator, non-recursively

I'm trying to create an Automator flow to copy some files from one folder to another folder. I only want to move files from the first level of the folder but Automator insists on finding files in subfolders withing the folder and moving them too. How can I stop Automator from recursively searching all the subfolders for files and just move the ones in the top level of the folder?

iMac, Mac OS X (10.4.10)

Posted on Nov 13, 2007 10:10 AM

Reply
5 replies

Nov 13, 2007 3:47 PM in response to CTnet

Considering that no specific 'Library' items, nor respective 'Action' items were provided, in the original post, the following code sample is one example.

01. Select the 'Library, Applications, Finder's 'Ask for Finder Items' Action.
02. Select the 'Library, Applications, Finder's 'Get Folder Contents' Action. Leave the 'Repeat for each subfolder found' check box un-checked.
03. Select the 'Library, Applications, Automator's 'View Results' Action.

The above works, as requested, here.

Nov 13, 2007 9:19 PM in response to dev_sleidy

This still gets folders in the given folder.

What if you only want to get the files in the given folder?

The filter action is far too limited, only giving three choices, and automator in general lacks a negation option.

I want to do something very similar:

1) find all files in ~/downloads, no subfolders
2) filter out folders so only files remain
3) move the files to another directory

I can't do number 2 or number 3 because there is no way to filter only files or find only non-folders, and number 3... I can only find copy actions, not move actions.

It seems like the finder section in Automater is pretty weak, and is missing tons of common file operations.

I'm searching for extra actions to fill in the gaps so any hints appreciated.

It seems to me that Leopard reduced the number of actions, even though I read in the feature list that there are more of them.

Is there some optional package you can install to get more automator actions?

Message was edited by: cshapple

Nov 14, 2007 6:26 AM in response to cshapple

cshapple's entry is a new subject, and should have been posted as such.

'This still gets folders in the given folder.' - yes, the 'Library' and related 'Actions', provided do list all items (files and folders) of the choosen folder; not, the contents of any sub-folders (of the choosen folder), as per the original posts request.

To obtain a list of only files -

In place of 02. above - select the 'Library, Applications, Automators 'Run AppleScript' Action. Then replace the contents of the 'Run AppleScript's textedit field with ..

on run {input, parameters}

try
tell application "Finder" to set input to files of folder (input as string)
end try

return input
end run

... One way to 'move' files - from one folder to another folder, on the same partition, is shown below.

on run {input, parameters}

try
tell application "Finder" to move (files of folder (input as string)) to folder (((path to desktop folder from user domain) as string) & "Test:")
end try

return input
end run

..., and yes - if the destination folder is on another partition, even the 'move' command actually 'copy's the item(s). It is left as an exercise for the programmer to determine if the destination folder is on another partition, and to delete the original items - after a guaranteed copy has been performed.

'It seems like the finder section in Automater is pretty weak, and is missing tons of common file operations.' - from Apple, yes; from others offering free 'Actions', no.

'Is there some optional package you can install to get more automator actions?' - no. Packages, yes.
See 1, 2, and 3.

Nov 14, 2007 8:48 AM in response to dev_sleidy

Actually cshapple's entry is to the point as I want only the files from the folder and not any contained folders or their contents. I'm not an Applescript expert and had hoped to use Automator instead, but, as dev_sleidy implies the use of Applescript is indicated here. I abandoned Automator and wrote the following Applescript that does what I need:

tell application "Finder"
select files in folder "Outbound EDI" of folder "EDI" of folder "Public" of folder "User_Name" of folder "Users" of startup disk
duplicate selection to folder "856 Folder" of folder "EDI" of folder "Public" of folder "User_Name" of folder "Users" of startup disk
move selection to folder "810 Folder" of folder "EDI" of folder "Public" of folder "User_Name" of folder "Users" of startup disk
end tell

I'm glad Applescript remains. Automator doesn't seem to have the flexibility or power yet.

This thread has been closed by the system or the community team. You may vote for any posts you find helpful, or search the Community for additional answers.

Copying and moving files with Automator, non-recursively

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