[alt.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

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";
}

jim@anacom1.UUCP (Jim Bacon) (09/10/90)

In article <MDB.90Sep8114446@kosciusko.ESD.3Com.COM> mdb@ESD.3Com.COM (Mark D. Baushke) writes:
>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
>

Here is a quick one I wrote to do the job a couple of years ago in C.
It might be useful to Michael (or others, like me :-) ) if perl is not
available. (I know, I know, just haven't had time to follow the
pacthes.)
---------------- cut here ----------------
#! /bin/sh
# This is a shell archive.  Remove anything before this line, then feed it
# into a shell via "sh file" or similar.  To overwrite existing files,
# type "sh file -c".
# The tool that generated this appeared in the comp.sources.unix newsgroup;
# send mail to comp-sources-unix@uunet.uu.net if you want that tool.
# If this archive is complete, you will see the following message at the end:
#		"End of shell archive."
# Contents:  mvlc.c
# Wrapped by jim@anacom1 on Mon Sep 10 00:15:52 1990
PATH=/bin:/usr/bin:/usr/ucb ; export PATH
if test -f 'mvlc.c' -a "${1}" != "-c" ; then 
  echo shar: Will not clobber existing file \"'mvlc.c'\"
else
echo shar: Extracting \"'mvlc.c'\" \(1697 characters\)
sed "s/^X//" >'mvlc.c' <<'END_OF_FILE'
X/*
X*	mvlc - move lowercase
X*	v1.0	8/20/88
X*	written by Jim Bacon, anacom1!jim
X*
X*	Convert an all uppercase filename to lowercase.  Names with lowercase
X*	letters will be ignored as will filenames which already have lowercase
X*	equivilents present.  Original filename will be removed from the
X*	directory if conversion is sucessful.
X*
X*	Usage - mvlc [FOOBAR.FIL]
X*/
X
X#include	<stdio.h>
X#include	<ctype.h>
X#include	<string.h>
X#include	<errno.h>
X#include	<sys/types.h>
X#include	<sys/stat.h>
X
X#define	TRUE	1
X
Xint	mv_lower();
Xchar	*convert();
X
Xmain(argc,argv)
X	int	argc;
X	char	*argv[];
X{
Xint		i;
Xchar		*lc_name;
Xstruct stat	sbuf;
X
X	if ( argc == 1 )
X		{
X		fprintf(stderr,"usage: mvlc file ...\n");
X		exit(2);
X		}
X
X	for ( i=1; i < argc; i++ )
X		{
X		if ( stat(argv[i],&sbuf) )
X			fprintf(stderr,"%s: stat() failed, errno %d\n",
X			   argv[i],errno);
X		else if ( sbuf.st_mode & 0070000 )
X			fprintf(stderr,"%s: not a regular file\n",argv[i]);
X		else if ( lc_name = convert(argv[i]) )
X			mv_lower(argv[i],lc_name);
X		}
X
X}
X
Xchar	*convert(uc_name)
X	char	uc_name[];
X{
Xstatic char	lc_name[BUFSIZ];
Xchar		*fname;
Xint		i,all_uc = TRUE;
X
X	strcpy(lc_name,uc_name);
X	fname = strrchr(uc_name,'/');
X	for ( i = fname ? ++fname - uc_name : 0;
X	    uc_name[i] && (all_uc = !islower(uc_name[i])); i++ )
X		lc_name[i] = tolower(uc_name[i]);
X	lc_name[i] = '\0';
X
Xreturn(all_uc ? lc_name : NULL);
X}
X
Xint	mv_lower(uc_name,lc_name)
X	char	*uc_name,*lc_name;
X{
Xint	mv_err;
X
X	if ( mv_err = link(uc_name,lc_name) )
X		fprintf(stderr,"%s: link() to %s failed, errno %d\n",
X		    uc_name,lc_name,errno);
X	else if ( mv_err = unlink(uc_name) )
X		fprintf(stderr,"%s: unlink() failed, errno %d\n",
X		    uc_name,errno);
X
Xreturn(mv_err);
X}

END_OF_FILE
echo shar: NEWLINE appended to \"'mvlc.c'\"
if test 1698 -ne `wc -c <'mvlc.c'`; then
    echo shar: \"'mvlc.c'\" unpacked with wrong size!
fi
# end of 'mvlc.c'
fi
echo shar: End of shell archive.
exit 0

-- 
Jim Bacon                            | "A computer's attention span is only
Anacom General Corp., CA             |  as long as its extension cord."
jim@anacom1.cpd.com                  |
zardoz!anacom1!jim                   |                                 Anon

les@chinet.chi.il.us (Leslie Mikesell) (09/11/90)

In article <374@anacom1.UUCP> jim@anacom1.UUCP (Jim Bacon, CPD Manager) writes:
>>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> maybe some kind of script ???

>>A perl script perhaps? [ deleted...]
>Here is a quick one in C. [deleted..]

Did I miss the obvious shell solution or didn't anyone bother to post it?

for i in *[A-Z]*
do
mv $i `echo $i|tr '[A-Z]' '[a-z]'`
done

There are some variations in the syntax for tr but I think that one should
work everywhere.
You might want to add a test for overwriting an existing destination file.

Les Mikesell
  les@chinet.chi.il.us

ken@csis.dit.csiro.au (Ken Yap) (09/11/90)

There's a program called xxu.c in the Kermit archives
(watsun.cc.columbia.edu) that will do what you want and more. It was
intended to convert files snagged via ftp having names like

	GLORK:<FOO.BAR.GAMES>TETRIS.ARC;1

to plain

	tetris.arc

pac@babcock.cerc.wvu.wvnet.edu (Michael A. Packer) (09/11/90)

From article <1990Sep11.041500.15152@chinet.chi.il.us>, by les@chinet.chi.il.us (Leslie Mikesell):
> In article <374@anacom1.UUCP> jim@anacom1.UUCP (Jim Bacon, CPD Manager) writes:
>>>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> maybe some kind of script ???


	Please stop sending me answers to this...

I would like to thanks EVERYONE that sent them..and trust me 
there are quite a few (>60)  

	Thank you all very much....

--
Michael A. Packer
===============================================================================
DARPA Initiative in Concurrent Engineering                                    =
PHONE:	304 293-7226                                                          =

pim@cti-software.nl (Pim Zandbergen) (09/11/90)

les@chinet.chi.il.us (Leslie Mikesell) writes:

>>>A perl script perhaps? [ deleted...]
>>Here is a quick one in C. [deleted..]
>Did I miss the shell solution or didn't anyone bother to post it?  [deleted..]

And the winner is:

#! /bin/ksh
typeset -l lower
for file in *[A-Z]*
do
	lower=$file
	mv $file $lower
done
-- 
Pim Zandbergen                          domain : pim@cti-software.nl
CTI Software BV                         uucp   : uunet!mcsun!hp4nl!ctisbv!pim
Laan Copes van Cattenburch 70           phone  : +31 70 3542302
2585 GD The Hague, The Netherlands      fax    : +31 70 3512837