in reply to Re^2: rename file name in directory and subdir
in thread rename file name in directory and subdir

I rarely work with windows, and can't check this on windows, so you would have to switch the file separators in this. Also, I'm not certain that it's entirely safe to modify the @pathList array from the subroutine during the for loop. In any case this works for me, changing all the filenames in folders from the original path downwards:

#! /usr/bin/perl use strict; use warnings; use diagnostics; my $originalPath = '/Path/To/file/'; my @pathList = ("$originalPath"); redoName($originalPath); for (@pathList) { redoName($_); } sub redoName { my $path = $_[0]; my @newName = split (/\//, $path); shift(@newName); my $newName = join(".", @newName); opendir (my $directory, $path) or die $!; while(readdir $directory) { my $fullName = "$path" . "$_"; unless (-d $fullName) { next if $_ =~ m/^\./; my $fileName = "$path" . "$newName" . ".$_";; rename $fullName, $fileName or die "couldn't r +ename: $!\n"; } if (-d "$fullName") { next if $_ =~ m/^\./; my $newPath = "$path" . "$_" . "\/"; push (@pathList, $newPath); } } }