develooper Front page | perl.beginners | Postings from February 2002

Re: Chaning case

Thread Previous
From:
Michael Kelly
Date:
February 28, 2002 21:58
Subject:
Re: Chaning case
Message ID:
B8A4589E.7E66%jedimike@mac.com
On 2/28/02 9:33 PM, Daniel Falkenberg <dan@vintek.net> wrote:

> G'day All,
> 
> Quick question I want to be able to change all folders in a directory to
> lower case?  Does any one know how I could do this using Perl?
> 
> Would I go something like this?
> 
> system('lc *');
> 
> well something like that... :)
> 
> Regards,
> 
> Dan

This seems a bit like a job for a shell script (I remember seeing one that
did just that once), but here's a script that changes all the files in the
current dir to lowercase:

##### CODE #####

#!/usr/bin/perl -w
use strict;

opendir(CWD,".");
my @files = readdir(CWD);
closedir(CWD);

foreach my $file (@files){
    my $lcfile = lc($file);
    print "$file -> $lcfile\n";
    rename($file,$lcfile);
}

##### END CODE #####

That should work on a *nix system. (the name passed to opendir() would be
":" on a Mac, and I'm-not-sure-what on Windows).

Hope that helps,
-- 
Michael


Thread Previous


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About