home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 11 Util
/
11-Util.zip
/
BOUNDUTI.ZIP
/
MRM.C
< prev
next >
Wrap
C/C++ Source or Header
|
1990-08-16
|
2KB
|
101 lines
/*
---------------------------------
mrm.c - file deletion utility
---------------------------------
written 8/15/90 by M. Mackey
*/
#define INCL_DOS
#include <os2.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
#define TRUE 1
#define FALSE 0
#define ATTR 0x0021
#define READ_ONLY 0x0001
#define LENGTH sizeof(buff)
static int yes(void);
static void report(char *format,char *arg);
static void error(char *fmt,char *arg1);
static void ChangeAttr(struct _FILEFINDBUF *buff);
int interactive = FALSE;
void main(int argc,char *argv[])
{
char pathname[_MAX_PATH],buf[10];
struct _FILEFINDBUF buff;
unsigned handle,count,rc;
for(argc--,argv++;argc && argv[0][0] == '-'; argc--,argv++)
switch(argv[0][1]) {
case 'i':
interactive = TRUE;
break;
default:
error("mrm: unknown option %s",argv[0]);
}
handle=0xffff;
for(;argc;argc--,argv++) {
count=1;
strcpy(pathname,*argv);
if(rc=DosFindFirst(pathname,&handle,ATTR,&buff,LENGTH,&count,0L))
if(rc==18)
error("mrm: file %s not found",pathname);
else
error("mrm: internal error %s",itoa((unsigned)rc,buf,10));
report("\nmrm '%s' [y/n]? ",buff.achName);
if(yes()) {
ChangeAttr(&buff);
DosDelete(buff.achName,0L);
}
while(TRUE) {
DosFindNext(handle,&buff,LENGTH,&count);
if(!count)
break;
report("\nmrm '%s' [y/n]? ",buff.achName);
if(yes()) {
ChangeAttr(&buff);
DosDelete(buff.achName,0L);
}
}
}
DosFindClose(handle);
exit(0);
}
void ChangeAttr(struct _FILEFINDBUF *buff)
{
unsigned attr;
if(buff->attrFile & READ_ONLY) {
report(" override read only [y/n]? ",NULL);
if(yes()) {
DosQFileMode(buff->achName,&attr,0L);
attr ^= READ_ONLY;
DosSetFileMode(buff->achName,attr,0L);
}
}
}
int yes(void)
{
if (interactive)
return (getche() == 'y');
else
return TRUE;
}
void report(char *format,char *arg)
{
if (interactive)
printf(format, arg);
}
void error(char *fmt,char *arg1)
{
printf(fmt, arg1);
exit(1);
}