home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / amiga / utility / misc / capit.lha / capit.c next >
Encoding:
C/C++ Source or Header  |  1992-06-20  |  2.3 KB  |  92 lines

  1.  
  2. /*
  3.  * Capit - by Robert Lang ⌐ EdgeWare
  4.  *
  5.  * A Simple program to Capitalize all files/directories in a directory,
  6.  * if this source is modified, the modified version must be sent to me :
  7.  *
  8.  *      Robert Lang
  9.  *      EdgeWare
  10.  *      P.O. Box 127
  11.  *      CARDIFF NSW 2285
  12.  *      AUSTRALIA
  13.  *
  14.  * No part of this source may be used in commercial software without
  15.  * written permission.
  16.  *
  17.  * Revision :
  18.  *
  19.  * 10th July 1991 - V1.0, Robert Lang.
  20.  *
  21.  */
  22.  
  23. #define VERSION "V1.0"
  24. #define TODAY "10th July 1991"
  25.  
  26. #include <stdio.h>
  27. #include <libraries/dos.h>
  28. #include <exec/types.h>
  29. #include <ctype.h>
  30.  
  31. /* main program */
  32.  
  33. main(int argc, char *argv[])
  34. {
  35.     /* get a read lock on the current directory */
  36.     struct FileLock *dir_lock;
  37.     struct FileInfoBlock info_block;
  38.     register BOOL stat;
  39.     char oldname[108],newname[108],path[80] = "",midname[108];
  40.  
  41.     if (argc > 2)
  42.     {
  43.         printf("\nCapit "VERSION" by Robert Lang "TODAY".\n\nUsage :\t"
  44.                "%s directory\n\nAnd all files/directories in that"
  45.                " directory will be capitalised.\n\n",argv[0]);
  46.         return;
  47.     }
  48.  
  49.     if (argc == 2)
  50.     {
  51.         if ((argv[1][strlen(argv[1])-1] == ':') || (argv[1][strlen(argv[1])-1] == '/'))
  52.             strcpy(path,argv[1]);
  53.         else sprintf(path,"%s/",argv[1]);
  54.     }
  55.  
  56.     if (dir_lock = (struct FileLock *)Lock(path,ACCESS_READ))
  57.     {
  58.       if (stat = Examine(dir_lock,&info_block))
  59.       {
  60.         stat = ExNext(dir_lock,&info_block);
  61.         while (stat)
  62.         {
  63.           printf("%s",info_block.fib_FileName);
  64.  
  65.           if (strlen(info_block.fib_FileName) < 8)
  66.             printf("\t\t\t");
  67.           else printf("\t\t");
  68.  
  69.           if (islower(info_block.fib_FileName[0]))
  70.           {
  71.             strcpy(midname,info_block.fib_FileName);
  72.             midname[0] = toupper(midname[0]);
  73.             printf("-> %s",midname);
  74.  
  75.             sprintf(newname,"%s%s",path,midname);
  76.             sprintf(oldname,"%s%s",path,info_block.fib_FileName);
  77.  
  78.             if (!Rename(oldname,newname))
  79.               printf(" (FAILED)\n");
  80.             else putchar('\n');
  81.           }
  82.           else printf("-> %s (unchanged)\n",info_block.fib_FileName);
  83.  
  84.           stat = ExNext(dir_lock,&info_block);
  85.         }
  86.       } else printf("Examine to directory failed.\n");
  87.  
  88.       UnLock(dir_lock);
  89.     }
  90.     else printf("Lock to directory failed.\n");
  91. }
  92.