[Date Index][Thread Index]
[Date Prev][Date Next][Thread Prev][Thread Next]

Re: BUG REPORT: Website META Language 1.7.1 (05-06-1999)



Jan Ulrich Hasecke <juh@pironet.de> writes:

> Fritz is right. It is better to name files like this: 19990608.wml.
> And I'll do it from now on, but it's boring to rename 266 files.

Agreed, this is boring. So you use a script:

#--- cut here and put into /usr/local/bin/rename ---
#!/usr/local/bin/perl
# The line above MUST be the first line of the script and you might have 
# to specify an different path if your perl executable lives somewhere else.

$op = shift;
if ($op eq '-n') { $op = shift; $pretend++; }
for (@ARGV) {
    $was = $_;
    eval $op;
    die $@ if $@;
    next if $was eq $_;
    if ($pretend) {
        print "would do: mv $was $_\n";
    } else {
        rename($was,$_) || die "rename: $!\n";
    }
}
#--- end of script ---


Now you say:

chmod +x /usr/local/bin/rename
/usr/local/bin/rename 's/^(\d{2})(\d{2})(\d{4}).wml$/$3$2$1.wml/' *wml

and you are all set.

rename takes any perl substitute expression as first argument and
applies it to the following arguments which must be filenames. It then
does a mv of the old filename to the new one.

You can also give rename a -n command line switch and it will tell you
what it WOULD do.

Cheers,
Fritz

______________________________________________________________________
Website META Language (WML)                www.engelschall.com/sw/wml/
Official Support Mailing List                   sw-wml@engelschall.com
Automated List Manager                       majordomo@engelschall.com