home *** CD-ROM | disk | FTP | other *** search
/ Turbo Toolbox / Turbo_Toolbox.iso / 1988 / 06_07 / trick / size.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-03-24  |  3.1 KB  |  106 lines

  1. /* ------------------------------------------------- */
  2. /*                    size.c                         */
  3. /*          gibt die Größe von Dateien aus           */
  4. /* ------------------------------------------------- */
  5.  
  6. #include <stdio.h>
  7. #include <dos.h>
  8.  
  9. char attr[8][9] = {
  10.                     " r/o",
  11.                     " hidden",
  12.                     " system",
  13.                     " volume",
  14.                     " subdir",
  15.                     " archive",
  16.                     " n/a",
  17.                     " n/a"
  18.                   };
  19.  
  20. char *index();
  21.  
  22. int isubdir( s )
  23. char s[];
  24. {
  25.   if(((strlen(s) == 1) && (s[0] == '.')) ||
  26.      ((strlen(s) == 2) && (s[0] == '.') &&
  27.      (s[1] == '.')))
  28.     return 1;
  29.   else
  30.     return 0;
  31. }                                         /* isubdir */
  32.  
  33. main( argc,argv )
  34. int  argc;
  35. char *argv[];
  36. {
  37.   char *pattern;          /* files to match          */
  38.   char dispsw = 1;        /* disp all files, def. on */
  39.   long total  = 0;        /* total size of files     */
  40.   int  files  = 0;        /* no of files             */
  41.   long size;              /* size of each file       */
  42.   int  i;
  43.   char mc;                /* attr                    */
  44.   char as[40];            /* attr str                */
  45.   struct FIND *p;         /* dir entry               */
  46.   char fname[9],ext[4];   /* filename                */
  47.   char *point;
  48.  
  49.   if(argc > 1)
  50.   {
  51.     for(i = argc; i > 0; i--)
  52.     {
  53.       if(*argv[i] == '-')
  54.       {
  55.         switch(*(argv[i]+1))
  56.         {
  57.           case 'n' :
  58.           case 'N' : dispsw = 0;
  59.                      break;
  60.          }
  61.        }
  62.        else pattern = argv[i];
  63.      }                                     /* for .. */
  64.  
  65.      p = findfirst( pattern, 0xff );
  66.      while(p != NULL)
  67.      {
  68.        size = p->size;
  69.        total += size;
  70.        files++;
  71.        as[0] = 0;
  72.        for(mc = 0; mc < 8; mc++)
  73.          {
  74.            if((p->attribute & (1 << mc)) != 0)
  75.            strcat(as,attr[mc]);
  76.        }
  77.        if(dispsw == 1)
  78.        {
  79.          if(((point = index(p->name,'.')) != NULL) &&
  80.             (isubdir( p->name ) == 0 ))
  81.          {
  82.            strncpy(fname, p->name, point - p->name);
  83.            fname[point - p->name] = '\0';
  84.            strncpy(ext, ++point, 4);
  85.            if((p->attribute & 0x10) == 0x10)
  86.              fprintf(stdout, "\n%-8s %-6s <DIR>  %s",
  87.                      fname, ext, as);
  88.            else
  89.               fprintf(stdout, "\n%-8s %-3s %8ld  %s",
  90.                       fname, ext, size, as);
  91.          }
  92.          else
  93.            fprintf(stdout, "\n%-15s <DIR>  %s",
  94.                    p->name, as);
  95.        }
  96.        p = findnext();
  97.      }                                   /* while .. */
  98.      if( total != 0 )
  99.        fprintf(stdout,
  100.              "\n\nTotal: %14ld   Bytes  %5d File(s)\n",
  101.              total,files);
  102.   }                                   /* if argc > 1 */
  103. }                                            /* main */
  104. /* ------------------------------------------------- */
  105. /*                 Ende von size.c                   */
  106.