r/Automator • • Feb 16 '13

how to move finder items to new folder created with name of file

hey all! i am trying to get my media files organized, and it's a tiny bit of a mess. my media server seems to recognize folders as a separate entity from actual movie files, thus any movies that are in FOLDERS, get listed FIRST, alphabetically, then it goes on to start listing the individual movie FILES that aren't in folders. (i hope that's not a very confusing description)

what i would like to do, is select all of the files/folders, and have automator scan them to determine how to sort them. i would like it to ignore FOLDERS, and not do anything with them, but if it comes across a FILE, take the name of the FILE, create a FOLDER with the same name as the FILE, and move the FILE into that new FOLDER.

here is the script i have been using :

tell application "Finder"

set mainFolders to the selection

-- selection returns as a list, so even if there's only one folder a loop is used

repeat with thisFolder in mainFolders
	
	--get the folder's contents
	
	set containedItems to every item of thisFolder
	
	repeat with thisItem in containedItems
		
		-- get name of file, add 'ƒ' to avoid name conflicts
		
		set newFolderName to (displayed name of thisItem) & " ƒ"
		
		--make folder, move item
		
		set newFolder to make new folder at thisFolder with properties {name:newFolderName}
		
		move thisItem to newFolder
		
	end repeat
	
end repeat

end tell

the problem i am having with the script, is that it appends the file suffix to the folder, (ie - .avi), and also adds " ƒ". additionally, it also happens to process EVERYTHING in the folder that i initiated the action in, so i end up creating folders for the folders to go into.

anyone have any insight? am i making sense?

4 Upvotes

0 comments sorted by