home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
OS2UTIL.ZIP
/
DU.C
< prev
next >
Wrap
Text File
|
1990-05-21
|
2KB
|
94 lines
#define INC_SUB
#define DIRECTORY 0x10
#define ALL_FILES 0x27
#include <os2.h>
#include <stdio.h>
#include <ctype.h>
#include <string.h>
long main(int argc, char* *argv);
long td(char *directory);
int clstr_sz;
long main(argc, argv)
int argc;
char **argv;
{
USHORT usDisk, usDrive;
ULONG usLogicalDriveMap;
FSALLOCATE FSInfoBuf;
char drive[3];
if (argc > 1)
usDisk = toupper(argv[1][0]) - '@';
if (argc == 1 || usDisk < 1 || usDisk > 26)
DosQCurDisk(&usDisk, &usLogicalDriveMap);
else
DosQCurDisk(&usDrive, &usLogicalDriveMap);
if (!(usLogicalDriveMap & (1 << (usDisk-1))))
{
printf("Invalid Drive %c: specified", usDisk + '@');
return 0;
}
if (DosQFSInfo(usDisk, 1, (PBYTE) &FSInfoBuf, sizeof(FSInfoBuf))) {
printf(" %c:", usDisk + '@');
puts(" ....Bad Drive Specifier....");
return 0;
}
clstr_sz = (int) (FSInfoBuf.cSectorUnit*FSInfoBuf.cbSector);
sprintf(drive, "%c:", usDisk+'@');
return td(drive);
}
long td(directory)
char *directory;
{
HDIR hdir = 0xFFFF;
USHORT usSearchCount = 1;
FILEFINDBUF findbuf;
char flname[80], sdir[64], *dir;
unsigned long bytes = 0l;
sprintf(flname, "%s\\*.*", directory);
if (!DosFindFirst(flname, &hdir, DIRECTORY, &findbuf,
sizeof(findbuf), &usSearchCount, 0L))
do {
if (strcmp(findbuf.achName, ".") && strcmp(findbuf.achName, "..") &&
findbuf.attrFile == DIRECTORY)
{
sprintf(sdir, "%s\\%s", directory, findbuf.achName);
bytes += td(sdir);
}
} while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
hdir = 0xFFFF;
usSearchCount = 1;
if (!DosFindFirst(flname, &hdir, ALL_FILES, &findbuf,
sizeof(findbuf), &usSearchCount, 0L))
do {
bytes += findbuf.cbFileAlloc;
} while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
bytes += clstr_sz;
dir = strchr(directory, '\\');
printf("%s\\ %lu K\n", (dir) ? dir : directory, bytes/1024);
return bytes;
}