Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
Re: renaming with number prefix
- X-seq: zsh-users 1266
- From: Peter Williams <williams@xxxxxxxxxxxxxxxxxxxx>
- To: ZShell Users <zsh-users@xxxxxxxxxxxxxxx>
- Subject: Re: renaming with number prefix
- Date: Fri, 23 Jan 1998 09:28:32 -0800
- In-reply-to: Your message of "Fri, 23 Jan 1998 16:54:04 +0100." <19980123165404.53612@xxxxxxxxxxxxxxxxx>
In message <19980123165404.53612@xxxxxxxxxxxxxxxxx>, Sven Guckes writes:
>Problem:
>Rename all files within a directory such that their names
>get a numeral prefix in the default sort order.
>
>Example:
>
> $ ls
> abc bar baz foo zyxxy
> $ <command>
> $ ls
> 1.abc 2.bar 3.baz 4.foo 5.zyxxy
I know I risk being branded a zsh heretic for posting two perl
solutions in one day, but here goes ;-)
usage: renumdir <directories>
renumdir () {
perl -e '{
foreach $dir (@ARGV) {
opendir(DIR,$dir) || die "Cannot opendir $dir: $!";
@files = sort grep(!/^\.\.?$/,readdir(DIR));
$num = "0" x length(@files);
chdir($dir);
for (@files) {
$file = $num++ . ".$_";
if (-f $file || !rename($_,$file)) {
warn "Cannot rename $_ -> $file: $!\n";
}
}
}
}' $*
}
Peter Williams <peter.williams@xxxxxxxxxxxx>
"Just don't create a file called -rf. :-)"
-- Larry Wall in <11393@xxxxxxxxxxxxxxxxxxxxxxx>
Messages sorted by:
Reverse Date,
Date,
Thread,
Author