use File::Spec::Functions qw( catfile ); # 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; if ($workdir =~ /^[a-zA-Z]:\z/) { $workdir .= '.'; # Fix bug in Windows. } print "Work dir = $workdir\n"; opendir(local *DIR, $workdir) 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 ".."); my $fqname = catfile($workdir, $name); if (-d $fqname){ # is this a directory? ScanDirectory($fqname); next; } print "Name = $name\n"; $newName = $name; $newName =~ s/\..*//; $newName .= ".xml"; my $new_fqname = catfile($workdir, $newName); $result = rename($fqname, $new_fqname) or die "Cannot rename $fqname to $new_fqame: $!"\n; } } $|=1; # Turn off I/O buffering ScanDirectory($ARGV[0]);