Filename => Creation date

21 06 2011

bored by manually sorting your photos? just rename all .jpg (or whatever filetype) files in the current directory to yymmdd_HHMMSS.jpg (or whatever filetype).
usage: $ filetodate $1
The passed variable ($1) is the filetype you want to rename. To be exact, the files in the current directory are filtered by $1. So beware that if you use ‘filetodate jpg’ and have a file named ‘ilovejpgs.txt’, this file will also be renamed.
This script can be easily adapted to your needs by changing the ‘d=$(date +…)’-line.

#!/bin/bash
files=$(ls | grep -i $1 )
echo 'Files:' $files
for i in ${files}
do
    e=${i#*.}
    d=$(date -r $i +%y%m%d_%H%M%S.$e)
    echo 'renaming' $i' to '$d
    mv $i $d
done
    echo 'new files:'
    ls

Advertisements

Actions

Information

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




%d bloggers like this: