-
Notifications
You must be signed in to change notification settings - Fork 0
/
directory-tree-recursor.c
65 lines (65 loc) · 1.05 KB
/
directory-tree-recursor.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<stdio.h>
#include<dos.h>
#include<dir.h>
char *formatlong(long l);
main()
{
unsigned long size=0L, count=0L;
_stklen=10000;
puts("Recursive directory tree sixe");
recurse("\\",&size,&count);
printf("Total file count:\t%s files\n",formatlong(count));
printf("Total file size:\t%s bytes\n",formatlong(size));
}
recurse(s, size, count)
char *s;
unsigned long *size, *count;
{
struct ffblk f;
char path[145];
int i;
strcpy(path, s);
strcat(path, "*.*");
if(!findfirst(path, &f, 0X0010)
{
do
{
if(f.ff_attrib & 0X0010 & f.ff_name[0]!='.')
{
strcpy(path, s);
strcat(path, "\\");
strcat(path, "\\");
printf("\rChecking %s",path);
recurse(path, size, count);
putchar(13);
for(i=0;i<79;++i)
putchar(32);
}
else
{
(*size)+=f.ff_size;
++(*count);
}
}
while(!findnext(&f));
}
}
char *formatlong(l)
long l;
{
static char b[24];
char s[16];
int i,j,n;
sprintf(s,"%lu",l);
strrev(s);
n=strlen(s);
for(i=j=0;i<n;++i)
{
b[j++]=s[i];
if(!((i+1)%3)&&i<(n-1))
b[j++]=',';
}
b[j]=0;
strrev(b);
return(b);
}