Need a "move any file from anywhere into subfolder by extension" scr..

I’m no scripter, but I believe that applescript is the tool for the job for what I need.

I’m looking for a way to select a file or group of files and run a script that will do the following:
1 - check the extension (example file: “file.psd”)
2 - check for a subfolder at current location (looks for subfolder called “psd files”)
3 - if subfolder exists, move file into it
4 - if subfolder does not exist, create it and move file into it

I need this to work on any file by individual extension, not kind.
I need it to work in any folder, either by dropping the files on a droplet or by right clicking on the files and running the script.
I need it to work only on selected files, not on an entire folder.

If anyone wants to tackle this, wonderful. I would really appreciate it. I would be happy to paypal a few bucks donation for your efforts if someone can make it work. If not, where do I go from here?

Thanks,
Gary

Hi Gary

welcome to MacScripter

try this, e.g. save it as application and drag it to the toolbar of any Finder window (next to the search bar).
You can either select files or drag it onto the icon

on open theseFiles
	process_Files(theseFiles)
end open

on run
	tell application "Finder" to set sel to selection
	process_Files(sel)
end run

on process_Files(theFiles)
	tell application "Finder"
		set here to insertion location
		repeat with oneFile in theFiles
			set Ex to name extension of oneFile
			if Ex is not "" then
				move oneFile to my make_new_folder(here, Ex & " files")
			end if
		end repeat
	end tell
end process_Files

on make_new_folder(theFolder, fName)
	try
		return ((theFolder as Unicode text) & fName) as alias
	on error
		tell application "Finder" to return (make new folder at theFolder with properties {name:fName}) as alias
	end try
end make_new_folder

That worked beautifully! Thanks. That’s really going to help me out organizing thousands of clients files. They’re already sorted into folders by project, but inside there, they will now be sorted by file type as well. Really cool. I was very happy to see that it even works on files with hidden or long extensions too.

If you will PM me your email address, I will paypal you a few bucks donation for your time.

Thanks again,
Gary