Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: Daft Regexp

by fourmi (Scribe)
on Aug 05, 2003 at 00:47 UTC ( [id://280849]=note: print w/replies, xml ) Need Help??


in reply to Daft Regexp

Forgot to log in initially
#!wperl use IO::File; use strict; my $dir = $ARGV[0]; chomp($dir); $dir =~ s{\\}{\\\\}g; Recurse($dir); sub Recurse { my $handle = shift; opendir(SPROUT,$handle); my @entries = readdir(SPROUT); closedir(SPROUT); foreach my $i (2..scalar(@entries)) { my $param_handle = $handle."\\".$entries[$i]; if(opendir(TEST,$param_handle) and $entries[$i]) { closedir(TEST); $handle =~ s{\\\\}{\\}g; my ($newdirname)= $handle."\\".$entries[$i]; $newdirname =~ s/^([a-z])/\u$1/g; rename ($handle."\\".$entries[$i], $newdirname); Recurse($newdirname); } elsif ($entries[$i]) { my ($newname) =$handle."\\".$entries[$i]; $newname =~ s/^([a-z])/\u$1/g; rename ($handle."\\".$entries[$i], $newname); } } }

And it doesn't seem to capitalise the first letter of dirs, and files... Could it be something else in the script?
cheers
ant

Replies are listed 'Best First'.
Re: Re: Daft Regexp
by jsprat (Curate) on Aug 05, 2003 at 01:21 UTC
    The problem is not the regex. Take a look at the values of $newname and $newdirname and the error messages. Look at the ouptut after adding

    rename ... or die "Error renaming $newname: $!"; #use $newdirname where appropriate

    to each rename statement.

    Since you are renaming _every_ file and directory, the whole rename sequence is practically begging to be taken out of the if/elsif statement.

    PS: You probably want to take a look at File::Find

Re: Re: Daft Regexp
by waswas-fng (Curate) on Aug 05, 2003 at 07:41 UTC
    Try using File::Find and doing a depth first search, its usually better practice (less error prone) to start renaming from the deepest part of the tree twords the top IMHO.

    -Waswas

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others learning in the Monastery: (2)
As of 2024-04-26 03:16 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found