home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 6 File
/
06-File.zip
/
hogger2.zip
/
SUBDIR.BAK
< prev
next >
Wrap
Text File
|
1994-02-07
|
2KB
|
85 lines
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <dos.h>
#include <dir.h>
#include <string.h>
#define START 1
#define NOTSTART 0
int RecurseSubDir(FILE *out, char *dirname, int start);
void main(int argc, char *argv[])
{
char ReadDir[60];
char dirname[60];
FILE *out;
if (argc<2) {
printf("Please supply a base directory parameter.\n");
}
strcpy(ReadDir,argv[1]);
strcpy(dirname,ReadDir); // Slide the parm in here.
if (NULL==(out=fopen("data.dat","wt"))){
printf("Can't write results.\n");
exit(1);
}
RecurseSubDir(out, dirname, START);
fclose(out);
}
int RecurseSubDir(FILE *out, char *dirname, int start)
{
struct ffblk ffblk;
int done=1;
int sum=0; // Sum for this directory.
int total=0; // Total of all subs + this one.
int index;
char name[60];
char fullname[60];
strcpy(fullname,dirname);
strcat(fullname,"\\*.*");
// Calcamount of data in this dir here.
// printf("Directory listing of *.*\n");
done = findfirst(fullname,&ffblk,0);
while (!done) {
done = findnext(&ffblk);
sum+=ffblk.ff_fsize;
}
total=sum;
index=0;
strcpy(name,".");
if(start){
fprintf(out,"%4c %8d %s \n",index+65, sum/1024, ffblk.ff_name);
}
strcpy(fullname,dirname);
strcat(fullname,"\\*.");
done = findfirst(fullname,&ffblk,FA_DIREC);
while (done==0){
if (0!=strcmp(ffblk.ff_name,".") && 0!=strcmp(ffblk.ff_name,"..")){
strcpy(name,dirname);
strcat(name,"\\");
strcat(name,ffblk.ff_name);
sum=RecurseSubDir(out, name, NOTSTART);
total+=sum;
if(start){
++index;
fprintf(out,"%4c %8d %s \n",index+65, sum/1024, ffblk.ff_name);
}
}
done=findnext(&ffblk);
}
return(total);
}