I recently had the need to rename a series of sequential files and add leading zeros to the number sequence within the filename.  i.e. I had files:

file-10.txt
file-1.txt
file-20.txt
file-5.txt
file-9.txt

and I wanted to rename them to:

file-01.txt
file-05.txt
file-09.txt
file-10.txt
file-20.txt

so they would be in lexical order and easier to read a directory listing of the files.

View full article »