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

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


Comment on Re^4: Transforming File Name Characters
Download Code
Re^5: Transforming File Name Characters
by choroba (Abbot) 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?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2014-10-23 13:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls