Friday, July 20, 2007

Renaming files in a directory

I recently completely a handy little $50 Project that ended up being immediately useful to me: a simple tool to rename a bunch of files in a given directory automatically.

Why might this be useful? Well...

  • What if you use some program that outputs a bunch of text files that you use later for something else, but it gives them archaic names and you want to give them all (there could be hundreds) more intuitive names?

  • What if you've got a long list of Word documents that you want to convert to text files?

  • What if you've got a lot of files relating to a project named "Secret Project" and all of a sudden the project gets renamed "Super Secret Project"?

  • What if you use Salesforce.com and you exported a whole list of attachments, but what you're left with is a bunch of hexadecimally named files with no file extension with an accompanying Excel file associating those hex names with their real English names and file extensions? (This, you might have guessed, is the issue I found myself with nearly immediately after having completed this project for my client, who was dealing with the first issue.

What I created is a simple file where the user can input the path to the directory in which the files are stored. Then the user lists the names of the files to be renamed in one column, and the new names and/or filetype extensions for each file in another column. Using the File System Object the macro finds the files in the list and renames them accordingly. It's remarkably fast, too.

To my Insiders subscribers, the file's on it's way.

Later,

Excel_Geek

Oh, and if you didn't already notice, I've decided to offer my originally created content on my blog to anyone who'd like to use it via a Creative Commons license. Do what you like with it -- commercial, non-commercial, make derivatives, whatever -- provided you attribute the original to me. I'm doing the same within the code modules in the files I send out to my Insiders subscribers. Enjoy!