in reply to Re^4: REVISED - Transforming File Name Characters
in thread Transforming File Name Characters
If $dir/$new already exists, you do not rename it. That's not what I think you want. What about this:
sub fixdir { my $dir = shift; opendir my $DH, $dir or die "Cannot open '$dir': $!"; while (my $f = readdir $DH) { next if grep $_ eq $f, qw/. ../; (my $new = $f) =~ s/[^a-zA-Z0-9_.]/_/g; if ($new ne $f) { $new .= '1' while -e "$dir/$new"; print STDERR "Renaming: $f -> $new\n"; rename "$dir/$f", "$dir/$new"; } fixdir("$dir/$new") if -d "$dir/$new"; } }
لսႽ† ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^6: FINAL - Transforming File Name Characters
by rfleisch (Initiate) on Mar 15, 2013 at 15:18 UTC |
In Section
Seekers of Perl Wisdom