everything and nothing

allskonar

Serializing a Bunch of Files

February 15th, 2009

One thing I do love is to spend 15 minutes to solve a problem that would have taken me 20 minutes to do manually … heck that’s how I got into this programming thing. Bash scripting is becoming one of my favorite tools as it’s so simple once you wrap your head around it’s weirdness … which I am hoping to do early 2010 :)

So the problem I had was that I had a bunch of photos with some stupid names which were automatically generated by my stupid scanner software, sc30rr.jpg not joking it was total rubbish so after spending roughly 30 minutes scanning photographs I had this folder filled with files with that stupid name and I just wanted to make it name_of_event_001 and have the last bit be a serialized number.


for filename in *.jpg ; \
  do n=$(( $n+1 )); \
  mv $filename name_of_event_`printf "%03d" $n`.jpg; \
done

My hope is next time I need to do this I will not have to fudge around for 15 minutes and just either remember how I did it this time or alternatively look it up on my blog :)

Sorry, comments are closed for this article.

Freyja Channel


last.fm recent tracks

allskonar Powered by Mephisto