Neat utility to convert uppercase filenames

Jay A. Snyder jay at gdx.UUCP
Sat Dec 8 05:39:51 AEST 1990


Did you ever do mget from simtel20 or ymodem batch downloads from an MSDOS
BBS, and get a lot of uppercase files in your directory?

Well this is a utility that will take all specified files and convert
them to lower case.

One exception is that trailing .Z's will be left uppercase

eg.

% ls
FILE.ZIP  FOO.BAR  TESTARC.TAR

% fdncase *
FILE.ZIP ==> file.zip
FOO.BAR.Z ==> foo.bar
TESTARC.TAR.Z ==> testarc.tar
%

----- snip snip -----
#include <stdio.h>
#include <stdlib.h>

usage()
{
  fprintf(stderr,"fdncase: File DowNcase\n");
  fprintf(stderr,"usage: fdncase file1 file2 ...\n");
  exit(0);
}

char *strtolcpy(d,s)
     char *s,*d;
{
  char *r;
  r=d;
  while (*d++=tolower(*s++));
  return(r);
}

#ifdef SYSV
rename(old,new)
     char *old,*new;
{
  int error;
  if (!(error=link(old,new)))
    {
      unlink(old);
      return(0);
    }
  else
    return error;
}
#endif

main(argc,argv)
     int argc;
     int *argv[];
{
  int i;
  char tmpstr[80];
  if (argc==1) usage();
  for (i=1;i<argc;++i)
    {
      if (strcmp(argv[i],strtolcpy(tmpstr,argv[i])))
	{
	  if (!rename(argv[i],tmpstr))
	    fprintf(stderr,"%s ==> %s\n",argv[i],tmpstr);
	  else
	    fprintf(stderr,"error renaming %s\n",argv[i]);
	}
      else
	{
	  fprintf(stderr,"%s already lower case\n",argv[i]);
	}
    }
}



More information about the Alt.sources mailing list