Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: File::Find finding . and ..

by jwkrahn (Abbot)
on Jul 15, 2009 at 17:18 UTC ( [id://780406]=note: print w/replies, xml ) Need Help??


in reply to File::Find finding . and ..

Your program, as presented, will not work.   Suppose that File::Find::find created a list something like:

/home/transiency/dir*one
/home/transiency/dir*one/file*one
/home/transiency/dir*one/file*two

After you rename '/home/transiency/dir*one' to '/home/transiency/dirone' then your program will not be able to find and rename '/home/transiency/dir*one/file*one' and '/home/transiency/dir*one/file*two' because '/home/transiency/dir*one' does not exist anymore.   You need something like:

#!/usr/bin/perl use warnings; use strict; use File::Find; our $VERSION = '0.1.3'; ### NAME NORMALIZER ### my $DIR = shift @ARGV; opendir TOCLEAN, $DIR or die "$DIR: $!"; my @dirs = map "$DIR/$_", grep -d "$DIR/$_" && !/\A\.\.?\z/, readdir T +OCLEAN; finddepth sub { ( my $new = $_ ) =~ tr!a-zA-Z0-9.~-!_!c; return if $new eq $_; rename $_, $new or warn "Cannot rename '$_' to '$new' $!"; }, @dirs;

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2024-04-18 00:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found