Deleting File types

Hi, new to scripting, have always made do with Automator before, but in this case I can’t get it to work with a network volume (it will only work if I copy files locally) and I have a large amount of folders to do. I’d like to be able to drop a few folders at a time on to it, so that it’s not too much of a load on the network in one go (to avoid crashes).

I want a droplet that will search through the folder and sub folders within dropped onto it to
delete all files that are PSD or AI.

I’d also if possible like it to look through the top folder and delete any sub folders
called “USA Archive” and/or a sub-folder that ends with the name “.2012”

I’ve searched through the forums and not been able to find anything. I’ve tried experimenting with copying and pasting bits of different examples where people have asked similar questions but can’t seem to get anywhere.

I’d be grateful if anyone could advise me. Thank you.

Welcome to the forum.

Try this:

on open of theFolders
	repeat with aFolder in theFolders
		set folderPath to quoted form of (POSIX path of aFolder)
		do shell script "find  " & folderPath & " -type d \\( -name \\*.2012 -o -name 'USA Archive' \\) -print0 | xargs -0 rm -df "
		do shell script "find  " & folderPath & " -type f \\( -name \\*.ai -o -name \\*.psd \\) -print0 | xargs -0 rm -f "
	end repeat
end open

Hi, Thank you for the fast response.

Unfortunately, it does not work. It just brings up the error message “Directory not empty”.

The -r didn’t make it in for some reason:

on open of theFolders
	repeat with aFolder in theFolders
		set folderPath to quoted form of (POSIX path of aFolder)
		do shell script "find " & folderPath & " -type d \\( -name \\*.2012 -o -name 'USA Archive' \\) -print0 | xargs -0 rm -drf "
		do shell script "find " & folderPath & " -type f \\( -name \\*.ai -o -name \\*.psd \\) -print0 | xargs -0 rm -f "
	end repeat
end open

Brilliant! Thank you so much! Wasn’t expecting to get such a fast and completely working exactly as I need. You have saved me an awful lot of head scratching.

Thank you again.