O
> I'm sure Lawrence or any other experienced perl monger could compress
> this down to about 2 lines including the #! but heres my  feeble attempt

Hey, why's everyone picking on me!!

> 
> #!/usr/bin/perl
> #
> my $newdir=shift or printusage();
> unless ($newdir=~m/.*\/$/){
>         $newdir="$newdir/";
> }
> 
> my $filename;
> my $counter =1;
>         foreach $filename (@ARGV){
>         warn $filename;
>         $filename=~m/.*(\..*$)/;
>         system("cp $filename $newdir/$counter$1");
>         $counter++;
> }
> 
> sub printusage{
>         print "Usage:  renamer dir filename [filename]\n";
> }

looks good, but misses out on the ascii-betical 01.jpg style.

Here's a shot

#!/usr/bin/perl -w

use strict;
use  File::Copy; 

die "Usage $0 File... directory\n" unless (@ARGV);
my $dir= $ARGV[$#ARGV];
 -d $dir || die "Last argument, $dir , is not a directory\n";;
$#ARGV--; #  remove directory from args

my $num= $#ARGV<100 ? '00': '000';
# keep images in ascii-betical order. works up to 1000 images

for(@ARGV){
   my $f=$_;

   next unless m/.*(\..*)$/;    # ignore files with no extension
   my $dest="$dir/${\($num++)}$1";
   copy ($f , $dest);   # or
   # move ($f , $dest); # alternatively
 }

cheers

Lawrence


--------------------------------------------------------------------
http://www.lug.org.uk                   http://www.linuxportal.co.uk
http://www.linuxjob.co.uk               http://www.linuxshop.co.uk
--------------------------------------------------------------------

Reply via email to