home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / tolower1.zip / TOLOWER.C < prev    next >
Text File  |  1997-09-21  |  4KB  |  109 lines

  1. /* (c) Copyright by Tels 1997. All Rigths Reserved.
  2.  
  3.   HACKed together from two examples from the online 
  4.   help - DosFindFirst/DosFindNext & rename    
  5.  
  6.   [09/19/97] Tels: Initial Version
  7.  
  8. */
  9.  
  10.   #define INCL_DOSFILEMGR   /* File Manager values */
  11.   #define INCL_DOSERRORS    /* DOS error values */
  12.   #include <os2.h>
  13.   #include <stdio.h>
  14.   #include <string.h>
  15.   #include <ctype.h>
  16.  
  17.  int convert(char* filename)
  18.  {
  19.     char NewName[256];
  20.     char dummyname [13] = "$$$$$$$$.TMP";
  21.     int i,j;
  22.  
  23.     printf (" %s ",filename);
  24.     j = strlen(filename);
  25.     strcpy (NewName, filename);
  26.     for (i=0; i<j; i++)
  27.        {
  28.        NewName[i] = tolower (NewName[i]);
  29.        }
  30.     if (strcmp (filename, NewName ) != 0)
  31.        {
  32.        if (rename(filename, dummyname) != 0)
  33.           {
  34.           printf(" Error: Could not rename file to $$$$$$$$.TMP. Skipped.");
  35.           }
  36.        else
  37.           if (rename(dummyname, NewName) != 0)
  38.              printf(" Error: Could not rename $$$$$$$$.TMP to file. Skipped.");
  39.           else
  40.              printf(" File is renamed to \"%s\".", NewName);
  41.        }
  42.     else
  43.        {
  44.        printf (" Warning: File already in lowercase. Skipped.");
  45.        }
  46.    printf ("\n");
  47.    return 0;
  48.  }
  49.  
  50.  
  51. int main (VOID) {
  52.      HDIR          hdirFindHandle = HDIR_SYSTEM;
  53.      FILEFINDBUF3  FindBuffer     = {0};      /* Returned from FindFirst/Next */
  54.      ULONG         ulResultBufLen = sizeof(FILEFINDBUF3);
  55.      ULONG         ulFindCount    = 1;        /* Look for 1 file at a time    */
  56.      APIRET        rc             = NO_ERROR; /* Return code                  */
  57.  
  58.     printf ("ToLower  v1.0 (c) by tels@pobox.com 1997.  All Rights Reserved.  \n\n");
  59.  
  60.      rc = DosFindFirst( "*.*",                /* File pattern - all files     */
  61.                         &hdirFindHandle,      /* Directory search handle      */
  62.                         FILE_NORMAL,          /* Search attribute             */
  63.                         &FindBuffer,          /* Result buffer                */
  64.                         ulResultBufLen,       /* Result buffer length         */
  65.                         &ulFindCount,         /* Number of entries to find    */
  66.                         FIL_STANDARD);        /* Return level 1 file info     */
  67.  
  68.      if (rc != NO_ERROR) {
  69.         printf("DosFindFirst error: return code = %u\n",rc);
  70.         return 1;
  71.      } else {
  72.         convert (FindBuffer.achName);
  73. //        printf ("%s\n", FindBuffer.achName);   /* Print file name             */
  74.  
  75.      } /* endif */
  76.  
  77.      /* Keep finding the next file until there are no more files */
  78.      while (rc != ERROR_NO_MORE_FILES) {
  79.         ulFindCount = 1;                      /* Reset find count.            */
  80.  
  81.         rc = DosFindNext(hdirFindHandle,      /* Directory handle             */
  82.                          &FindBuffer,         /* Result buffer                */
  83.                          ulResultBufLen,      /* Result buffer length         */
  84.                          &ulFindCount);       /* Number of entries to find    */
  85.  
  86.         if (rc != NO_ERROR && rc != ERROR_NO_MORE_FILES) {
  87.            printf("DosFindNext error: return code = %u\n",rc);
  88.            return 1;
  89.         } else {
  90.            convert (FindBuffer.achName);
  91.      //      printf ("%s\n", FindBuffer.achName);    /* Print file name */
  92.  
  93.         }
  94.      } /* endwhile */
  95.  
  96.      rc = DosFindClose(hdirFindHandle);    /* Close our directory handle */
  97.      if (rc != NO_ERROR) {
  98.         printf("DosFindClose error: return code = %u\n",rc);
  99.         return 1;
  100.      }
  101.      return NO_ERROR;
  102.      printf ("\nAll done. Have a nice day.\n");
  103.   }
  104.  
  105.  
  106.  
  107.  
  108.  
  109.