help moving files to different folders based on names

ok I’m working on this workflow thing that will take my tv shows downloaded and automatically convert them for my apple tv. But I want to add a part where it will move each show to a specific folder for that show. So lets say like I get show A so then it is converted and moved to folder A then show B would go to folder B. Since the file names arent always exactly consistent I think you could use like a move here if file name contains “x”. If some one could help me it would be much appreciated I really have no idea how to start it.

Hi,

for example you can write something like this


set movieFolder to path to movies folder

set theFiles to {"list of files"}
tell application "Finder"
	repeat with oneFile in theFiles
		set showName to name of file oneFile -- syntax depends on class of the source list files
		if showName contains "A" then
			move oneFile to folder "A" of movieFolder
		else if showName contains "B" then
			move oneFile to folder "B" of movieFolder
		end if
	end repeat
end tell

you can also use lists to avoid endless if - else queries

thank you so much, I would like it so I could just be able to add a couple of more lines to the script for more different files so could i just add another.

else if showname contains “c”…

or what would a list look like it might be better if i have alot of shows.

Also I really have no idea where to add my info i need in there can you give some note of where to add my directories for movie folders and stuff

Thank You


property stringList : {"stringA", "stringB", "stringC"}
property FolderList : {"folderA", "folderB", "folderC"}

set movieFolder to path to movies folder

theFiles to {"list of files"}
repeat with oneFile in theFiles
	set showName to name of (info for oneFile as alias) -- syntax depends on class of the source list files
	set flag to false
	repeat with i from 1 to (count stringList)
		if showName contains item i of stringList then
			set flag to true
			exit repeat
		end if
	end repeat
	if flag then
		tell application "Finder" to move oneFile to folder (item i of FolderList) of movieFolder
	end if
end repeat

thank you again I know i add the show title and folder title to stringA and folder A part. But then what else in there do i have to add my own information, or nothing at all. I’m really new at this

the list stringList contains the strings to be searched for
the list folderList contains the string paths (colon delimited) of the folders relative to the movie folder of your home folder.
You can also put in absolute paths then you have to remove of movieFolder in the move line.
Or you can specify another base folder by changing the argument in set moviefolder line, which must be an alias or Finder file specifier
the list theFiles with the dummy “list of files” must contain the files to be processed

ok awesome for my sake the folder i want to make this a folder action for is at Volumes:My Book:TV so the script would look like this


property stringList : {"stringA", "stringB", "stringC"}
property FolderList : {"folderA", "folderB", "folderC"}

set movieFolder to Volumes:My Book:TV --My Location for my moviesfolder

theFiles to {"list of files"}
repeat with oneFile in theFiles
   set showName to name of (info for oneFile as alias) -- syntax depends on class of the source list files
   set flag to false
   repeat with i from 1 to (count stringList)
       if showName contains item i of stringList then
           set flag to true
           exit repeat
       end if
   end repeat
   if flag then
       tell application "Finder" to move oneFile to folder (item i of FolderList) of movieFolder
   end if
end repeat

would that work then to make it a folder action that would activate when i file is dropped in the location My Book:TV would i just add it to automator then export as folder action or is there another way to do it.

a folder action is a good solution and could look like


property stringList : {"stringA", "stringB", "stringC"}
property FolderList : {"folderA", "folderB", "folderC"}

on adding folder items to this_folder after receiving theseItems
	set movieFolder to alias "My Book:TV:" --My Location for my moviesfolder
	repeat with oneFile in theseItems
		set showName to name of (info for oneFile)
		set flag to false
		repeat with i from 1 to (count stringList)
			if showName contains item i of stringList then
				set flag to true
				exit repeat
			end if
		end repeat
		if flag then
			tell application "Finder" to move oneFile to folder (item i of FolderList) of movieFolder
		end if
	end repeat
end adding folder items to

well i put an example string for a file “colbert” and a folder Colbert Report saved it as a script and attached it as folder action to My Book:TV and i dropped a file The.Colbert.Report.08.12.2008.DSR.Xvid-0TV.[VTV].mp4 in the folder and nothing happened it didnt sort it to the colbert report folder

I used this script

property stringList : {"colbert", "stringB", "stringC"}
property FolderList : {"Colbert Report", "folderB", "folderC"}

on adding folder items to this_folder after receiving theseItems
	set movieFolder to alias "MY BOOK:TV:" --My Location for my moviesfolder
	repeat with oneFile in theseItems
		set showName to name of (info for oneFile)
		set flag to false
		repeat with i from 1 to (count stringList)
			if showName contains item i of stringList then
				set flag to true
				exit repeat
			end if
		end repeat
		if flag then
			tell application "Finder" to move oneFile to folder (item i of FolderList) of movieFolder
		end if
	end repeat
end adding folder items to

The script should work.
The path of the destination folder is “MY BOOK:TV:Colbert Report” and the folder must exist
Folder action scripts must be located in (~)/Library/Scripts/Folder Action Scripts
and make sure that folder actions are enabled

thank you I tried it and it worked after like a delay though. But then i tried it again and it seems to no go this time wierd.