[comp.sources.wanted] lowercase routine.

pac@cathedral.cerc.wvu.wvnet.edu (Michael A. Packer) (09/07/90)

does anyone have a routine which can be compiled on UNIX that
will read the current directory and convert all upcase names
to lowercase?

if there was a file called 

READ.ME it would simply be converted to read.me

maybe some kind of script ???

please send responses to 

pac@cerc.wvu.wvnet.edu

thanks in advance.


pac


--
USMAIL:	Drawer 2000, Concurrent Eng. Res. Center, WVU, Morgantown, WV 26506
PHONE:	304 293-7226
INTERNET : pac@cerc.wvu.wvnet.edu

ts@uwasa.fi (Timo Salmi LASK) (09/08/90)

In article <745@babcock.cerc.wvu.wvnet.edu> pac@cathedral.cerc.wvu.wvnet.edu (Michael A. Packer) writes:
>does anyone have a routine which can be compiled on UNIX that
>will read the current directory and convert all upcase names
>to lowercase?

No guarantees, but try taking a look at the /unix/ts directory at
chyde.uwasa.fi using anonymous ftp.

...................................................................
Prof. Timo Salmi        (Moderating at anon. ftp site 128.214.12.3)
School of Business Studies, University of Vaasa, SF-65101, Finland
Internet: ts@chyde.uwasa.fi Funet: gado::salmi Bitnet: salmi@finfun

mdb@ESD.3Com.COM (Mark D. Baushke) (09/09/90)

On 7 Sep 90 15:31:31 GMT, pac@cathedral.cerc.wvu.wvnet.edu (Michael A.
Packer) said:

Michael> does anyone have a routine which can be compiled on UNIX that
Michael> will read the current directory and convert all upcase names
Michael> to lowercase?

Michael> if there was a file called 
Michael> READ.ME it would simply be converted to read.me

Michael> maybe some kind of script ???

A perl script perhaps? See below.
-- 
Mark D. Baushke
mdb@ESD.3Com.COM

#!/usr/local/bin/perl
#
# rename-uppercase-files.pl --- rename uppercase files to lowercase
# 
# Author          : Mark D. Baushke
# Created On      : Sat Sep  8 11:23:23 1990
# Last Modified By: Mark D. Baushke
# Last Modified On: Sat Sep  8 11:36:54 1990
# Update Count    : 1
# Status          : Alpha release 0.1
# 

# Convert any files in the given directories with uppercase file names
# into lowercase file names. Default to using the current directory.

unshift(@ARGV, '.') if $#ARGV < $[; # if no dir args use current directory
directory:
    while($ARGV = shift) {
    if (! -d ($dir = $ARGV)) {
	print STDERR "Usage: $0 [directory]...\n".
	    	     "$dir is not a directory...skipped\n";
	next directory;
    }

    # Get all files in the dir. Use readdir since it is faster than
    # globbing, but also because we should to include .-files.
    opendir (DIR, $dir) || die "$!: $dir\nStopped";
    @all = readdir (DIR);
    closedir (DIR);

    print STDERR "Processing '$dir' begins.\n";
    $cnt = 0;
    for $file ( @all ) {
	# If a file has an uppercase character in it it should be converted
	if ($file =~ /[A-Z]/) {
	    ($newfile = $file) =~ tr/A-Z/a-z/;
	    # Do not clobber any existing files
	    if ( -e $dir."/".$newfile ) {
		print STDERR "$dir/$newfile already exists. ".
		             "$dir/$file not renamed.\n";
	    }
	    else {
		rename($dir."/".$file, $dir."/".$newfile) ||
		    die "Unable to rename $dir/$file: $!";
		$cnt++;
	    }
	}
    }
    print STDERR "Processing '$dir' complete. $cnt files renamed.\n";
}

mpogue@dg-rtp.dg.com (Mike Pogue) (09/11/90)

In article <1990Sep7.204741.21613@uwasa.fi>, ts@uwasa.fi (Timo Salmi
LASK) writes:
|> In article <745@babcock.cerc.wvu.wvnet.edu>
pac@cathedral.cerc.wvu.wvnet.edu (Michael A. Packer) writes:
|> >does anyone have a routine which can be compiled on UNIX that
|> >will read the current directory and convert all upcase names
|> >to lowercase?

  This is a relatively simple program using 'perl', which can be found
on
most archive sites.  

Mike Pogue
Data General

Speaking for myself alone....

davet@cbnewsj.att.com (Dave Tutelman) (09/11/90)

In article <745@babcock.cerc.wvu.wvnet.edu> pac@cathedral.cerc.wvu.wvnet.edu (Michael A. Packer) writes:
>does anyone have a routine which can be compiled on UNIX that
>will read the current directory and convert all upcase names
>to lowercase?

This isn't "compiled", but I've been using the following shell script
for about a year with no problems:

--------------------
# Rename file arguments to have all lower-case names,
# but don't overwrite existing files.

for FILE in $* 
do
	NEWNAME=`echo $FILE | grep [A-Z] | tr [A-Z] [a-z]`
	if [ "a$NEWNAME" != "a" ]
	then
		if [ -s $NEWNAME ]
		then
			echo "mvlower: $NEWNAME already exists"
		else
			echo "mvlower: renaming $FILE to $NEWNAME"
			mv $FILE $NEWNAME
		fi
	fi
done
----------------------------

If you store this script as "mvlower", then you can do what you want with

	mvlower *

Cheers!
Dave
+---------------------------------------------------------------+
|    Dave Tutelman						|
|    Physical - AT&T Bell Labs  -  Lincroft, NJ			|
|    Logical -  ...att!pegasus!dmt == dmt@pegasus.att.com	|
|    Audible -  (201) 576 2194					|
+---------------------------------------------------------------+

glaeske@plains.NoDak.edu (Brian Glaeske) (09/11/90)

Here is the program to put filenames in lowercase.  Have a blast with it.

--Cut Here--
#!/bin/csh
set progname = `basename $0`
foreach file ($*)
        set newname = `echo $file | tr A-Z a-z`
        if  -f $newname then
                echo ${progname}: Will not overwrite ${newname}.
        else
                echo ${progname}: \[$file\]\    -\> \[$newname\]
                mv $file $newname
        endif
end
--Cut Here--



-- 
Brian Glaeske
 -  /|                        glaeske@plains.NoDak.edu  [Internet] 
  o.O`   --Ooop ACK!!         glaeske@plains            [BITNET  ]
=(___)=                       ..!uunet!plains!glaeske   [UUCP    ]
   U    "Bloom County Forever!!"