use Cwd; # module for finding the current working directory $|=1; # turn off I/O buffering # This subroutine takes the name of a directory and recursively scans # down the filesystem from that point looking for files named "core" sub ScanDirectory{ my ($workdir) = shift; print "Work dir = $workdir\n"; my ($startdir) = &cwd; # keep track of where we began chdir($workdir) or die "Unable to enter dir $workdir:$!\n"; opendir(DIR, ".") or die "Unable to open $workdir:$!\n"; my @names = readdir(DIR) or die "Unable to read $workdir:$!\n"; closedir(DIR); foreach my $name (@names){ next if ($name eq "."); next if ($name eq ".."); if (-d $name){ # is this a directory? &ScanDirectory($name); next; } else { # this is a file print "Name = $name\n"; $newName = $name; $newName =~ s/\..*//; $newName .= ".xml"; $result = rename($name, $newName) or die "cannot rename $name to $newName:$!"; } chdir($startdir) or die "Unable to change to dir $startdir:$!\n"; } } &ScanDirectory($ARGV[0]);