#!/usr/bin/perl
#
# This script 'll rename files - remove a char from a name.
#
use File::Find;
use Cwd;
use strict;

### deine vars 
my $charfrom=":";
my $charto="_";
my $debug=undef;
### internal vars
my (%dirlist,@filelist,$file,$choice);

### function(s) definition(s)

# returns a list of files in a directory
# assumes that a directory path cannot be anything but absolute path.
# assumes that 'll run from find(), thus doesn't load $_.
sub getfilelist
{my ($cdir,$debug); $debug=0;
 $debug && print "$File::Find::dir :\t\t$_\n";
 #some checks on file name & type
 unless ( -l "$File::Find::name" ) # we won't follow symlinks.
    {unless ( -d "$File::Find::name" ) # skip dirs.
      {unless ( "$_" eq "." )
        {unless ( "$_" eq ".." )
          {push (@filelist,"$File::Find::name");}
        }
      }
    }

} # sub getfilelist

### start work
my $usedir=getcwd; # too lazy to get it from cmdline - too much code for too simple task..
print "This will rename files containing '$charfrom', replacing it with '$charto'.\n";
print "This will be done at current directory - '$usedir'.\n";
print "Press <Enter> to continue or ^C to quit.\n";
$choice=<STDIN>;
@filelist=();
find (\&getfilelist,$usedir);
foreach $_ (@filelist)
{$debug && print "original file: $_\n";
 $file="$_";
 if (/$charfrom/)
 {s/$charfrom/$charto/;
  $debug && print "new file:      $_\n";
  system ("mv -i $file $_");
 }
}

