home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 6 File / 06-File.zip / hogger2.zip / SUBDIR.CPP < prev    next >
C/C++ Source or Header  |  1994-02-07  |  2KB  |  85 lines

  1. #include <stdio.h>
  2. #include <conio.h>
  3. #include <stdlib.h>
  4. #include <dos.h>
  5. #include <dir.h>
  6. #include <string.h>
  7.  
  8.  
  9. #define START 1
  10. #define NOTSTART 0
  11. int  RecurseSubDir(FILE *out, char *dirname, int start);
  12.  
  13. void main(int argc, char *argv[])
  14. {
  15.     char ReadDir[60];
  16.     char dirname[60];
  17.     FILE *out;
  18.  
  19.     if (argc<2) {
  20.         printf("Please supply a base directory parameter.\n");
  21.     }
  22.     strcpy(ReadDir,argv[1]);
  23.  
  24.     strcpy(dirname,ReadDir);        // Slide the parm in here.
  25.  
  26.     if (NULL==(out=fopen("data.dat","wt"))){
  27.         printf("Can't write results.\n");
  28.         exit(1);
  29.     }
  30.  
  31.     RecurseSubDir(out, dirname, START);
  32.  
  33.     fclose(out);
  34. }
  35.  
  36. int  RecurseSubDir(FILE *out, char *dirname, int start)
  37. {
  38.     struct ffblk ffblk;
  39.     int done=1;
  40.     int sum=0;                                            // Sum for this directory.
  41.     int total=0;                                        // Total of all subs + this one.
  42.     int index;
  43.     char name[60];
  44.     char fullname[60];
  45.  
  46.  
  47.     strcpy(fullname,dirname);
  48.     strcat(fullname,"\\*.*");
  49.  
  50.     // Calcamount of data in this dir here.
  51. //    printf("Directory listing of *.*\n");
  52.     done = findfirst(fullname,&ffblk,0);
  53.     while (!done) {
  54.         done = findnext(&ffblk);
  55.         sum+=ffblk.ff_fsize;
  56.     }
  57.     total=sum;
  58.  
  59.     index=0;
  60.     strcpy(name,".");
  61.     if(start){
  62.         fprintf(out,"%4c %8d %s \n",index+65, sum/1024, "<Selected Dir>");
  63.     }
  64.     strcpy(fullname,dirname);
  65.     strcat(fullname,"\\*.");
  66.     done = findfirst(fullname,&ffblk,FA_DIREC);
  67.     while (done==0){
  68.         if (0!=strcmp(ffblk.ff_name,".") && 0!=strcmp(ffblk.ff_name,"..")){
  69.             strcpy(name,dirname);
  70.             strcat(name,"\\");
  71.             strcat(name,ffblk.ff_name);
  72.  
  73.             sum=RecurseSubDir(out, name, NOTSTART);
  74.             total+=sum;
  75.             if(start){
  76.                 ++index;
  77.                 fprintf(out,"%4c %8d %s \n",index+65, sum/1024, ffblk.ff_name);
  78.             }
  79.         }
  80.         done=findnext(&ffblk);
  81.     }
  82.     return(total);
  83. }
  84.  
  85.