home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 592b.lha / XTime_v1.0 / source / getfilenames.c next >
C/C++ Source or Header  |  1991-11-23  |  2KB  |  83 lines

  1. /* Get filenames and sizes which match wildcard string */
  2.  
  3. #include <libraries/dos.h>
  4. #include <ctype.h>
  5.  
  6. void ExtractPath();
  7. extern int NoCase();
  8. extern wildmat();
  9. char name[30], path[50], filename[31];
  10.  
  11. struct FileInfoBlock fi;
  12.  
  13. FindFiles(filepath)
  14.  
  15. char filepath[80];
  16.  
  17. {
  18.   long size, lock, total = 0;
  19.   int bool, error;
  20.   char tempstr[31];
  21.  
  22.   ExtractPath(filepath);
  23.   lock = Lock(path, ACCESS_READ);
  24.   if (!lock)
  25.     {
  26.       printf("Unable to lock; probably an invalid pathname.\n");
  27.       exit(FALSE);
  28.     }
  29.  
  30.   if (Examine(lock, &fi))
  31.     do
  32.       {
  33.       /* If we're not at the end, and if it's not a directory...*/
  34.       if ((*fi.fib_FileName != 0) && (fi.fib_DirEntryType < 0))
  35.         {
  36.         strcpy (tempstr, fi.fib_FileName);
  37.         bool = wildmat(tempstr, name);
  38.         if (bool > 0)
  39.           {
  40.           printf ("%-31s%7ld\n", fi.fib_FileName, fi.fib_Size);
  41.           total += fi.fib_Size;
  42.           }
  43.         }
  44.       }
  45.     while (ExNext(lock, &fi));
  46.   error = IoErr();
  47.   if(error != ERROR_NO_MORE_ENTRIES)
  48.     printf("Error %d occurred!\n", error);
  49.   return (total);
  50. }
  51.  
  52.  
  53. void ExtractPath(pathname)
  54.  
  55. char pathname[80];
  56.  
  57. {
  58.   int i, j = 0;
  59.   i = strlen(pathname);
  60. /* Extract filename */
  61.   while (pathname[i-1] != '/' && pathname[i-1] != ':' && i != 0)
  62.     name[j++] = pathname[--i];
  63.   reverse(name);
  64.  
  65. /* Build pathname */
  66.   j = 0;
  67.   while (j < i)
  68.     path[j++] = pathname[j];
  69. }
  70.  
  71. reverse(s)
  72. register char *s;
  73. {
  74.    register int c, i, j;
  75.  
  76. for(i=0, j = strlen(s) - 1; i < j; i++, j--)
  77.   {
  78.    c    = s[i];
  79.    s[i] = s[j];
  80.    s[j] = c;
  81.   }
  82. }
  83.