Larry’s Filename Fixer for Windows

Reading Raymond’s post about bulk file renaming reminded me of Larry Wall’s filename fixer. This is a great thing to have in your toolbox. Here’s a minor tweak that allows it to work in Windows CMD.exe.

I call this renamer.cmd to avoid conflict with CMD’s much-less-useful built-in rename.


@rem = '
@echo off
perl -w %~f0 %*
exit /B %ERRORLEVEL%
';

# rename - Larry's filename fixer
$op = shift or die "Usage: renamer expr [files]\n";
chomp(@ARGV = <STDIN>) unless @ARGV;

# cmd.exe doesn't do glob expansion
@ARGV = map glob, @ARGV;

for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    rename($was,$_) unless $was eq $_;
}

Update:
Oops! Who woulda thunk that the first Google hit for “Larry’s filename fixer” would be a book warez site? Link changed to point at Google’s Usenet archive.

Advertisements

1 Response to “Larry’s Filename Fixer for Windows”


  1. 1 beaker January 13, 2009 at 1:22 pm

    Thanks for the fix. Sweet and simple.


Comments are currently closed.




%d bloggers like this: