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

RE: Chaning case

Thread Previous | Thread Next
From:
Timothy Johnson
Date:
February 28, 2002 23:15
Subject:
RE: Chaning case
Message ID:
C0FD5BECE2F0C84EAA97D7300A500D5002581013@SMILEY
 
The current directory notation in Windows is also ".", but I'd be interested
to see if Windows will let you do it that way, since to the OS "MyDir",
"MYDIR", and "mydir" are all the same name.  If you are using Windows you
might end up having to do it in two steps; one changing the name to a
temporary name, and another changing it to lowercase.

-----Original Message-----
From: Michael Kelly
To: beginners@perl.org
Sent: 2/28/02 9:58 PM
Subject: Re: Chaning case

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


-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org


--------------------------------------------------------------------------------
This email may contain confidential and privileged 
material for the sole use of the intended recipient. 
If you are not the intended recipient, please contact 
the sender and delete all copies.

Thread Previous | Thread Next


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