(mis)adventures in software development...

10 October 2011

Batch rename of filenames to lowercase

Category Unix

I must have done something terrible in a past life, for as part of my day job I have to maintain software written in Visual Basic. Version 6. Yes, version 6. And it’s 2011. I’ve checked my watch. Twice.

The Visual Basic abomonation is only a small part of a much larger Unix-based client-server system — the VB applications are the GUI front end. It’s interesting that even when doing Windows development, remarkably often I find the need to do something that would be easily accomplished on a Unix box, but is innordinately difficult to do on a Windows machine. Even as a (power) user, I’m increasingly finding I’m more productive, not to mention less annoyed, with the user experience on my Linux box at work, compared to my Windows 7 machine at home. (Although both Linux and Windows GUI environments have things that annoy me.)

In fact, pretty much the only compelling argument I’ve heard to justify the relative expense of purchasing a Mac is that underneath the eye-candy and consumer friendly front-end of OS X, there lies the power of Unix, for those that might want or need it. Although to be fair, PowerShell does go some way towards solving simple cases of where one might need some command-line goodness. But that would mean having to learn PowerShell.

And so once again I find myself in a situation where Windows unnecessarily gets in my way, but thankfully I have access to a Unix system, which allows me to easily fix the problem at hand relatively easy. In this case, the problem is that one of the many, many, many annoyances I am faced with is Visual Basic’s tendency to change the case of filenames that are part of the project. This is not normally an issue in the case-insensitive world of Windows. But these pieces of Visual Basic detritus are parts of a mainly Unix system, so therefore it is on the Unix side of things where the source code version control is handled, and where what should be a simple act of committing code changes inevitably become a 3 act tragedy, often involving much time working with Emacs ediff mode.

Fortunately, doing batch renames on Unix/Linux is fairly straightforward thanks to the rename command. So to ensure all files in the current directory with a “.frm” extension have all lowercase filenames:

      rename 'y/A-Z/a-z/' *.frm

Easily fixed on just about any Unix/Linux system, thank you Larry Wall. Try doing that on any out-of-the-box Windows installation — without the tedium of endless pointing and clicking. Or learning PowerShell.