home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
OS2UTIL.ZIP
/
RMD.C
< prev
next >
Wrap
Text File
|
1990-05-21
|
1KB
|
56 lines
#define INCL_SUB 1
#define DIRECTORY 0x10
#include "os2.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
int main(int, char**);
int dd(char*);
main(argc, argv)
int argc;
char *argv[];
{
if (argc != 2) {
puts("format: rmd <directory path>");
exit(-2);
}
return(dd(argv[1]));
}
dd(directory)
char *directory;
{
HDIR hdir = 0xFFFF;
USHORT usSearchCount = 1, retcode, ret = 0;
FILEFINDBUF findbuf;
char path[20], flname[30];
strcpy(path, directory);
strcat(path, "\\");
strcpy(flname, path);
strcat(flname, "*.*");
if (!DosFindFirst(flname, &hdir, 0x37, &findbuf,
sizeof(findbuf), &usSearchCount, 0L))
do {
strcpy(flname, path);
strcat(flname, findbuf.achName);
if (findbuf.attrFile == DIRECTORY) {
if (findbuf.achName[0] != '.')
ret += dd(flname);
}
else {
DosSetFileMode(flname, 0x00, 0L);
if (DosDelete(flname, 0L)) {
printf("Cannot delete %s\n", flname);
exit(-1);
}
}
} while (!DosFindNext(hdir, &findbuf, sizeof(findbuf), &usSearchCount));
if (retcode = DosRmdir(directory, 0L))
printf("Cannot delete subdirectory: %s\n", directory);
return(retcode+ret);
}