#!/usr/bin/perl -w
#
# Name: put_txt_previous_to_filename
# puts text previous to filename
# remark "./" at the beginnig of the produced command for mv because of the dash of the filename, interpreted as option by mv
# writes batch to $bat_file
# 
# by Gerd Hoffmann (C)
#
# 1211019

use strict;

my $txt = "Coimbra-" ;
my $bat_file = "ren-files" ;
my ( $name, @dirlist ) ;
my $dir = "./"  ;
my $no_begin = 10 ;

opendir(DIR, $dir) || die "no $dir ?: $!";
foreach  $name (sort (readdir(DIR)) ) {
   if ( defined($name) ) {
      if ( -d $name ) { next; }
      else {
         (@dirlist) = (@dirlist, $name);
#         print "$name\n"; 
      }
   }
}

closedir(DIR);

#print "$#dirlist\n" ;

open(BATCH,">$bat_file") || die "Could not create $bat_file: $!" ;
for ( my $i=0; $i <= $#dirlist; $i++ ) {
#   printf ("mv %s %03d-%s\n", $dirlist[$i], $no_begin, $dirlist[$i] ) ;
   printf BATCH ("mv %s %s%s\n", $dirlist[$i], $txt, $dirlist[$i] ) ;
#   $no_begin++ ;
}
print BATCH "unlink $bat_file" ;
#print BATCH "unlink ($txt-$bat_file, $bat_file)" ;
close(BATCH) ;
chmod(0755, $bat_file) ;

__END__
