OS X: Move files based on creation date

I wanted to organize my flip videos – I wanted them moved into a folder named after their creation date.

One of the scripts that I found uses ls’s “–time-style” parameter. BSD’s ls does not have this value. MacPorts’ coreutils port contains gls (GNU’s ls) that does support the parameter. So here is my script to move movies into a sub folder based on the movies creation date.

for filename in *.MP4; do
    datepath="$(gls -l --time-style=+%Y-%m-%d $filename | awk '{print $6}')"
    echo "$datepath"
    if ! test -e "$datepath"; then
        mkdir -pv "$datepath"
    fi
    mv -v $filename $datepath
done

, ,

Comments are closed.