Copy of directory tree after thinning

I would like to know if this is possible/easy with automator:
I need a copy of a directory tree (folders and subfolders) that only contains jpg, gif and other images. I need to retain the directory structure (empty folders are OK), but remove non-image files. I can use three letter file extensions to differentiate the image files.
For example,

parent/folder/images/one.jpg
parent/folder/images/two.jpg
parent/folder2/images/one.gif
parent/folder2/text2.txt
parent/text.txt
parent/three.jpg

would become:

parent/three.gif
parent/folder/images/one.jpg
parent/folder/images/two.jpg
parent/folder2/images/one.jpg

My backup plan is to write a perl script, but I wonder if Automator would be easier? I have almost no experience with Automator and thus am not sure where to begin. Any help is appreciated.

TIA,
derekhed

Model: MacBook Pro
AppleScript: 2.2.1?
Browser: Safari 525.27.1
Operating System: Mac OS X (10.5)

Derek:

I have playing with Automator trying to get it to do what you want, but it cannot filter the difference between a file and a folder. Well, at least I cannot make it do that. Anyway, here is an AppleScript that should do the job for you:

tell application "Finder"
	set a to every file of entire contents of (choose folder) whose kind does not contain "image"
	repeat with aa in a
		move aa to trash
	end repeat
end tell

Depending on how many trees are in the chosen folder, and how many files need to be removed, this could take a few minutes to complete. I am confident a perl or shell script would be faster, but I am not well versed in those things.

Good luck,

Hey I appreciate your response! :slight_smile:

I don’t know enough about Automator to know when it is the best tool to use, but it seems very promising for a lot of things.

I’ll give your script a whirl, thanks again.

Derekhed