bb1 /* zdir.c Rapporterar fil-katalogers totala storlek */ /* av Jesper N„sstr”m f”r Svenska PC World */ /* */ #define __MSC /* G”r Borlands DOS.H kompatibel med Microsoft */ #include #include #include #ifdef __TURBOC__ #include #else #include #endif #define ATTRIBUTES _A_NORMAL | _A_RDONLY | _A_HIDDEN | \ _A_SYSTEM | _A_VOLID | _A_ARCH | _A_SUBDIR void makepath(char *path, char *drive, char *dir, char *fname, char *ext) { if(dir[strlen(dir)-1] != '\\') /* katalognamn ska sluta med '\' */ strcat(dir, "\\"); sprintf(path, "%s%s%s%s", drive, dir, fname, ext); /* sl† ihop */ } unsigned long dirsum(char *pathstr, int pf) { struct find_t ffblk; /* inneh†ller filattribut med mera */ int f, fcount = 0; unsigned long subsum, bytesum = 0L; /* summa filstorlek */ char drivestr[_MAX_DRIVE], dirstr[_MAX_DIR]; char subdir[_MAX_DIR], nextpath[_MAX_PATH]; int done; _splitpath(pathstr, drivestr, dirstr, NULL, NULL); done = _dos_findfirst(pathstr, ATTRIBUTES, &ffblk); while(!done) { if(((ffblk.attrib & _A_SUBDIR) == 0) /* det „r en vanlig fil */ || (ffblk.name[0] == '.')) { /* eller "." eller ".."-katalog */ bytesum += ffblk.size; if (pf) printf (" %13s %8ld \n", ffblk.name, ffblk.size); goto nextfile; } sprintf(subdir, "%s%s", dirstr, ffblk.name); /* path n„sta niv† */ makepath(nextpath, drivestr, subdir, "*", ".*"); subsum = dirsum(nextpath, 0); /* Rekursivt anrop */ bytesum += subsum; if (pf) printf(" %13s %8ld Directory\n", ffblk.name, subsum); done = _dos_findfirst(pathstr, ATTRIBUTES, &ffblk); for(f=0; f