Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'Batch rename image files sequentially via perl script' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
Batch rename image files sequentially via perl script
Authored by: rudedog on Aug 29, '07 09:57:32AM

The Perl distribution actually comes with a perl program called rename that you can use to do all kinds of rename tasks. It isn't installed on OSX by default, but you could get a copy from the perl distribution.

Using rename to do your task is easy:

rename -n 's/^/sprintf("%03d_", $::iter++)/e' *.jpg

The -n flag means "dry run" - it only tells you what it will do without doing it. Using the rename command rather than rolling your own is much safer, because it will never overwrite existing files and with the -n switch you can easily see what's going to happen.



[ Reply to This | # ]
Batch rename image files sequentially via perl script
Authored by: regeya on Sep 03, '07 11:47:33AM

I used this a few months ago to help sanitize a tree I'd copied over from HFS+ to a Linux machine running Netatalk. Netatalk expects some characters to be encoded a certain way, and rename did just the trick.

Anyone know why the OS X Perl distribution doesn't ship with this?



[ Reply to This | # ]