Batch converting filenames to/from hex?
August 28, 2006 11:43 AM   Subscribe

Is there a good way to convert an entire directory of numbered files from hex to decimal notation or vice versa? For example, I'll have files named AK00.txt AK03.txt and AK1F.txt that I want to convert to AK00.txt AK03.txt and AK31.txt. I've considered writing a shell script to do this, but if a solution already exists, I would love to hear about it. Thanks!
posted by idontlikewords to Computers & Internet (5 answers total)
The perl hex command converts a hex number to a decimal number. Combined with some regex, it should make writing a little script pretty easy.
posted by chrisamiller at 12:16 PM on August 28, 2006

There are a ton of these batch renaming programs available, so you might want to try a few and find out which ones work best for you. Here are a few free ones:

Renamer 6
Rename Master
posted by LuckySeven~ at 12:35 PM on August 28, 2006

Something like:

perl -e 'while(<>) { /AK([0-9a-f][0-9a-f])\.txt/i && rename $_ "AK". hex($1) . ".txt";}'

perhaps (warning, not well tested !)
posted by pharm at 1:52 PM on August 28, 2006

If you you're in a UNIXish environment with a standard Perl installation, you have a rename command.

rename 's{AK(\d+)\.txt}{sprintf("renamed/AK%02X.txt", $1)}e' AK*.txt

Replace 'renamed' with whatever destination directory you want -- be sure to avoid any naive solution that does this in place, potentially clobbering files as it goes.
posted by Zed_Lopez at 1:55 PM on August 28, 2006

Thanks guys... I am not the best at regex, so this is great to get me started!
posted by idontlikewords at 2:31 PM on August 28, 2006

« Older The Holy Grail: Honest car mechanic in LA?   |   Flashcards Newer »
This thread is closed to new comments.