Beefy Boxes and Bandwidth Generously Provided by pair Networks
We don't bite newbies here... much

Re^4: Transforming File Name Characters

by rfleisch (Initiate)
on Mar 14, 2013 at 17:53 UTC ( #1023516=note: print w/replies, xml ) Need Help??

in reply to Re^3: Transforming File Name Characters
in thread Transforming File Name Characters

I have a question regarding this statement... sub fixdir { my $dir = shift; opendir my $DH, $dir or die "Not Found....$dir: $!"; while (my $f = readdir $DH) { next if grep $_ eq $f, qw/. ../; (my $new = $f) =~ s/[^a-zA-Z0-9_.]/_/g; next if ($new eq $f); <<<<<<<<<<<<< THIS ONE <<<<<<<<<<<< +<<<< while ( -e "$dir/$new") { $new.= "1"; } print STDERR "Renaming: $f -> $new\n"; rename "$dir/$f", "$dir/$new"; fixdir("$dir/$new") if -d "$dir/$new"; } } IF $f is the name of a directory and not a file won't that whole direc +tory get skipped????? Thanks -Ray

Replies are listed 'Best First'.
Re^5: Transforming File Name Characters
by choroba (Chancellor) on Mar 14, 2013 at 18:06 UTC
    Yes, you are right. You should only skip the renaming part, not the recursive one. This problem did not exist in my code, though (but something like unless $new eq $f should be appended to the rename).

    Also, please do not use <code> tags for normal text. It makes the code harder to download.

    لսႽ ᥲᥒ⚪⟊Ⴙᘓᖇ Ꮅᘓᖇ⎱ Ⴙᥲ𝇋ƙᘓᖇ

      10-4 on only using the "code" tag for real code. I was using it for formatting. But if I understand your code correctly the script would "die" at the first duplicate, which I do NOT want it to do.

      -Regards, -Ray

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1023516]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (10)
As of 2016-10-25 13:12 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (319 votes). Check out past polls.