Move File to Alphabetical Folders Based on Name and Extension

Discussion in 'Mac Programming' started by aeronauticsrock, Feb 29, 2012.

  1. aeronauticsrock macrumors member

    Jan 30, 2010
    Hi Everyone,

    I'm in the process of ripping my DVD collection and want to automate the workflow of moving the .dvdmedia files and .m4v files from my desktop to alphabetical folders on an external HD.

    I know how to do it in automater (very tedious and I'm sure the worst way) by finding .dvdmedia and .m4v files on the desktop, checking if the filename starts with an A, and then moving it to the A folder. The problem is that this would require me to set up 104 automator actions- 2 for each letter, and 1 each for .dvdmedia and .m4v.

    So I am looking for the "better way". I am not extremely good with Applescript but I know some of the basics. For reference, the external hard drive structure looks like:

    2TB External
    /DVD Rips​
    /Full Movies​

    Thanks in advance for any guidance!
  2. MasConejos macrumors regular


    Jun 25, 2007
    Houston, TX
    I'm not an apple script person so I cant help you there, unfortunately, however I can point you at a retail product that I believe does what you want: Hazel

    If you don't want to spend the money, I can offer ruby scripting advice instead
  3. sero macrumors member

    Aug 28, 2008
    I would just use a simple bash script..

    ## Guessing the paths..
    dvd_rips="/Volumes/2TB\ External/Movies/DVD\ Rips"
    full_movies="/Volumes/2TB\ External/Movies/Full\ Movies"
    for i in $(ls ~/Desktop/|egrep '(.m4v|.dvdmedia)'); do
    	dest_dir=$(echo "$i"|tr [:lower:] [:upper:]|cut -c1)
    	if [ "$(echo "$i"|rev|cut -d'.' -f1|rev)" == "m4v" ]; then
    		mv "~/Desktop/${i}" ${full_movies}/${dest_dir}/
    		echo "moving "$i" to ${full_movies}/${dest_dir}/"
    	elif [ "$(echo "$i"|rev|cut -d'.' -f1|rev)" == "dvdmedia" ]; then
    		mv "~/Desktop/${i}" ${dvd_rips}/${dest_dir}/
    		echo "moving "$i" to ${dvd_rips}/${dest_dir}/"

Share This Page