Script for sorting files into folders

I use this on my downloads folder for sorting files into folders based on strings in the filename. You need a folder tree, for example:
and in the above, any incoming files with 'Dave' anywhere in their names will be moved to the 'Dave' folder, any with 'Pete' in the Pete folder .... etc. Matches are case insensitive.
Use:
Create a new rule and add a "Passes Shell script" condition, Embedded script. Edit the script, copy the script below into it, change the RootFolder variable to the full path of your folder tree and set the shell to /bin/bash. Bish, Bosh.
Comment out the growlnotify line if you don't have growl installed.
Enjoy
- Code: Select all
Main
Dave
Pete
Harry
and in the above, any incoming files with 'Dave' anywhere in their names will be moved to the 'Dave' folder, any with 'Pete' in the Pete folder .... etc. Matches are case insensitive.
Use:
Create a new rule and add a "Passes Shell script" condition, Embedded script. Edit the script, copy the script below into it, change the RootFolder variable to the full path of your folder tree and set the shell to /bin/bash. Bish, Bosh.
Comment out the growlnotify line if you don't have growl installed.
Enjoy
- Code: Select all
#script:
RootFolder=/Users/Kim/Downloads/Movies
# split only on new line
OLDIFS="$IFS" # save it
IFS="
"
file="$1"
for folder in $(ls -1 $RootFolder/) ; do
ufolder=`echo $folder | tr "[:upper:]" "[:lower:]"`
ufile=`echo $file | tr "[:upper:]" "[:lower:]"`
if grep -q $ufolder <<< $ufile ; then
mv $file to $RootFolder/$folder
/usr/local/bin/growlnotify -m "Moved $file to $folder in Movies" MovieMover
exit 0
fi
done
IFS=OLDIFS
exit 1