Thursday, September 13, 2012

bulk rename of file extensions

When the software that drives my scanner on my mac saves PDF files it uses the extension ".PDF".  I would like to have the extension ".pdf" on the files.

I accomplished this by renaming the files using this shell snippet:

for x in *.PDF; do
  y="`echo "$x" | sed -e s/\.PDF$/.pdf/g`"
  mv -i "$x" "$y-"
  mv -i "$y-" "$y"

There are two moves because the file system acts case insensitive and recognizes the initial and final file name as the same. Also the file name variables are quoted because of spaces in the file names.

No comments:

Post a Comment