Not enough arguments for rename at line 22, near "$eachFile)"
####
use strict;
use warnings;
sub re_name
{
my $path = $_[0];
#append a trailing / if it's not there
if($path !~ /\/$/)
{
$path .= '/';
}
#loop through the files contained in the directory
for my $eachFile (glob($path.'*'))
{
#if the file is a directory
if(-d $eachFile)
{
#pass the directory to the routine ( recursion )
re_name($eachFile);
}
else
{
my @strings = split('/', $eachFile);
my $fileName = $strings[$#strings];
my $filePath = '/'.join('/', @strings[2..$#strings-1]);
system("mv $filePath/$fileName $filePath/newfile");
}
}
}
re_name('.');
re_name('/tmp/654653');
####
$ mkdir -p /tmp/654653
$ cd /tmp/654653
$ mkdir -p FOO/BAR
$ mkdir -p FOO/TZE
$ touch FOO/BAR/BANANA
$ touch FOO/BAR/APPLE
$ touch FOO/TZE/ORANGE
$ perl 654653.pl
mv: cannot stat `//654653.pl': No such file or directory
mv: cannot stat `/BAR/APPLE': No such file or directory
mv: cannot stat `/BAR/BANANA': No such file or directory
mv: cannot stat `/TZE/ORANGE': No such file or directory
mv: cannot stat `/654653/654653.pl': No such file or directory
mv: cannot stat `/654653/FOO/BAR/APPLE': No such file or directory
mv: cannot stat `/654653/FOO/BAR/BANANA': No such file or directory
mv: cannot stat `/654653/FOO/TZE/ORANGE': No such file or directory
####
use strict;
use warnings;
use File::Find;
my $path = '.';
finddepth(\&pattern, $path);
sub pattern {
print "$_\n";
rename($_, lc($_));
}
__END__