Category : File Managers
Archive   : NDEL2.ZIP
Filename : NDEL2.C
Output of file : NDEL2.C contained in archive : NDEL2.ZIP
* NAME HEADER: FILE : NDEL2.C (not delete for OS/2 and DOS) *
* AUTHOR: RAJESH NIHAL, compuserve [73427,1377] *
* DATE : 6/11/90 UPDATE: 7/14/91 *
* SYS : OS/2 1.x xE *
* PROG : NDEL2 version 0.1 Copyright (c) 1991 RAJESH NIHAL*
* REMARK: This program will delete all the files, Except *
* those which are specified on the command line. *
* Use this program as you wish (except abusing it).*
* If distributting, leave the name of the header *
* (this whole commented block) intact and *
* do not change the run time help screen. I am NOT *
* responsible for any damages(so far works great). *
* Comments, Advises, Corrections are welcome. Next *
* version will have wildcard support. *
* PS : THIS PROGRAM IS NOT A SHAREWEAR. DO NOT USE *
* WILDCARDS, IF USED WILL WIPE OUT EVERYTHING. *
* THE FILE[S] WHICH YOU SPECIFY ON THE COMMAND *
* LINE SHOULD NOT CONTAIN DIR PATH. THE PROGRAM *
* WILL NOT DELETE ITSELF. *
* *
* Compiler: MSC 6.00A *
* Compilation syntax: cl /A{
* Runtime arguments: ndel2
* Special: Use BIND under DOS to create a family exe *
***************************************************************************/
/******************************* HEADER FILES ******************************/
#include
#include
#include
#include
#include
#include
/******************************* DEFINES AND MACROS ************************/
#define read_only 0x01
#define archive 0x20
#define getdir getcwd(buffer,128)
/******************************* GLOBAL VARS *******************************/
unsigned extern far pascal \
DosFindFirst(char far *, unsigned far *, unsigned, void far *, \
int, int far *, unsigned long);
// The above prototype produces warnings.
// Maybe the type of the arguments has been changed for MSC 6.00A?
/* .
.
.
more prototypes
.
.
.
*/
int getfiles(void);
int delete_file(char *);
int tempargc;
char near buffer[128]; // Buffer size could vary
int err,i;
char temp[100][12];
char probuf[128];
unsigned hand = -1;
int ms = 1;
struct buu { // DosFind{First/Next} return struct
unsigned dt,tm,dtt,tmm,dttt,tmmm;
long fs,flc;
unsigned ft;
char fc;
char fn[13]; // This is used in the program
} bu;
/******************************** MAIN MODULE ******************************/
int main(int argc,char *argv[])
{
int f;
register int targc;
int pro;
if (argc == 1)
{
printf("\a\n\n");
puts("Required parameter missing!");
//argv[0] [strlen(argv[0]) - 4] = NULL; don't work under OS/2
printf("Synopsis: %s file[s].\n",argv[0]);
printf("Use %s [/? /h[H] -? -h[H] ? ] for help screen.\n",argv[0]);
exit (1);
}
if(argc > 1)
{
if((strcmp(argv[1],"/?")==0) || (strcmp(argv[1],"/h")==0) ||
(strcmp(argv[1],"-h")==0) || (strcmp(argv[1],"-?")==0) ||
(strcmp(argv[1],"-H")==0) || (strcmp(argv[1],"/H")==0) ||
(strcmp(argv[1],"?")==0))
{
printf("%s Version 0.1 Copyright (c) 1991 RAJESH NIHAL\n",argv[0]);
printf("\nThis Utility Deletes all the files, except those specified");
printf(" on the command line\n");
printf("Syntax is : %s FILE(S) leave a space between files.\n",argv[0]);
printf("Example : %s cc.exe all the files except cc.exe will be deleted.\n",argv[0]);
printf("Example : %s awk.exe bc.exe prjcnvt.txt comp.txt\n",argv[0]);
printf("\aNO WILDCARDS!!\n");
exit (1);
}
/*************************** EXTRACT THE NAME OF THE PROGRAM ****************/
pro = 0;
for(i=(strlen(argv[0])-1);i>=0;i--)
{
if(argv[0][i] == '\\')
break;
else
probuf[pro] = argv[0][i];
pro++;
}
strrev(probuf);
/*************************** SAVE THE GIVEN FILE NAMES **********************/
tempargc = argc; /* why :')@#*&%? */
targc = tempargc;
i = 0;
while (argc != 1)
{
getdir;
strcpy(temp[i],argv[argc-1]);
if (strlen(buffer) > 3) // if !root
strcat(buffer,"\\");
strcat(buffer,temp[i]);
if(!DosFindFirst (buffer,&hand,0x20|0x00,\
(void far *)&bu,sizeof(bu),&ms,0L))
for(f=0;f <= 81;f++)
{
buffer[f] = 0;
}
else
{
printf("%s not found ...program aborted.\n",temp[i]);
exit(-1);
}
argc--;
i++;
}
argc = targc;
/************************* MAKE THE GIVEN FILES READ ONLY *******************/
i = 0;
DosSetFileMode(probuf,0x01,0);
while(argc != 1)
{
DosSetFileMode(temp[argc-2],0x01,0);
i++;
argc--;
}
argc = targc;
/******************** FIND THE REMAINING FILES AND DELETE THEM **************/
getfiles(); // Just to make the program more readble
/************************* MAKE THE GIVEN FILES ARCHIVE ********************/
while(argc != 1)
{
DosSetFileMode(temp[argc-2],0x20,0);
argc--;
}
/***************************************************************************/
DosSetFileMode(probuf,0x20,0); /* change the attrib of program to archive */
} /* if argc > 1 */
DosFindClose(hand);
return 0;
} /* end main module */
/***************************************************************************/
int delete_file(char *filename) /* delete all the files */
/***********
* input: filename
* output: Delete that file
* Notes : Could have made nice inline function if OOP was Supported
* Could have made a macro too.
***********/
{
#ifdef SHOW_NAMES // Undocumented feature for NDEL2
// Don't get nervous looking at the file names on screen
printf("deleting %s\n",filename);
#endif
DosDelete(filename,0);
return 0;
}
/***************************************************************************/
int getfiles(void) /* get all the files */
{
int done;
getdir;
if (strlen(buffer) > 3)
strcat(buffer,"\\*.*"); /* current dir and all the files */
else
strcat(buffer,"*.*"); /* current root dir and all the files */
done = DosFindFirst(buffer,&hand,0x20|0x00,\
(void far *)&bu,sizeof(bu),&ms,0L); /* get first file */
delete_file(bu.fn); /* delete that file*/
while (!done)
{
done = DosFindNext(hand,(void far *)&bu,\
sizeof(bu),&ms); /* find next file */
err = delete_file(bu.fn); /* delete that file */
}
return 0;
}
Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!
This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.
But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/