home *** CD-ROM | disk | FTP | other *** search
- /***************************************************************************
- * NAME HEADER: FILE : NDEL.C (not delete) *
- * AUTHOR: RAJESH NIHAL, compuserve [73427,1377] *
- * DATE : 9/11/90 *
- * SYS : DOS 3.0 and up *
- * PROG : NDEL version 0.3 Copyright (c) 1990 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 BE PRESENT IN THE CURRENT DIRECTORY. *
- ***************************************************************************/
-
- /******************************* HEADER FILES ******************************/
- #include <stdio.h>
- #include <dir.h>
- #include <dos.h>
- #include <string.h>
-
- /******************************* DEFINES AND MACROS ************************/
- #define read_only 0x01
- #define archive 0x20
- #define getdir getcwd(buffer,MAXPATH)
- #define readonly_prog(attr,name) regs.h.ah = 0x43;\
- regs.h.al = 0x01;\
- regs.x.cx = attr;\
- regs.x.dx = (unsigned) name;\
- intdos(®s, ®s);
-
- #define archive_prog(attr,name) regs.h.ah = 0x43;\
- regs.h.al = 0x01;\
- regs.x.cx = attr;\
- regs.x.dx = (unsigned) name;\
- intdos(®s, ®s);
- /******************************* GLOBAL VARS *******************************/
- int get_file(void);
- int delete_file(char near *);
- int tempargc;
- char near buffer[MAXPATH];
- int err,i;
- char temp[100][12];
- union REGS regs;
- struct ffblk ffblk;
- char probuf[MAXPATH];
-
- /******************************** MAIN MODULE ******************************/
- int main(register 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;
- printf("Synopsis: %s file[s].\n",argv[0]);
- puts("Use NDEL [/? /h[H] -? -h[H] ? ] for help screen.");
- 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("NDEL Version 0.3 Copyright (c) 1990 RAJESH (RISC) NIHAL\n");
- printf("\nThis Utility Deletes all the files, except those specified");
- printf(" on the command line\n");
- printf("Syntax is : NDEL FILE(S) leave a space between files.\n");
- printf("Example : NDEL tc.exe all the files except tc.exe will be deleted.\n");
- printf("Example : NDEL tcc.exe tc.exe prjcnvt.txt comp.txt\n");
- exit (0);
- }
- /*************************** 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;
- /* this is because C compiler will not store the
- value of tempargc after this loop, why I don't know */
- targc = tempargc;
- i = 0;
- while (argc != 1)
- {
- getdir;
- strcpy(temp[i],argv[argc-1]);
- strcat(buffer,"\\");
- strcat(buffer,temp[i]);
- if(!findfirst(buffer,&ffblk,0))
- 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;
- readonly_prog(read_only,probuf);
- while(argc != 1)
- {
- readonly_prog(read_only,temp[argc-2]);
- i++;
- argc--;
- }
- argc = targc;
-
- /******************** FIND THE REMAINING FILES AND DELETE THEM **************/
-
- getfiles();
-
- /************************* MAKE THE GIVEN FILES ARCHIVE ********************/
- while(argc != 1)
- {
- archive_prog(archive,temp[argc-2]);
- argc--;
- }
- /***************************************************************************/
-
- archive_prog(archive,probuf); /* change the attrib of program to archive */
- } /* if argc > 1 */
-
- return 0;
- } /* end main module */
-
- /***************************************************************************/
- int delete_file(char near *filename) /* delete all the files */
- {
- /* function 41h */
- regs.h.ah = 0x41; /* delete file */
- regs.x.dx = (unsigned) filename;
- intdos(®s, ®s); /* intr 21h */
-
- return 0;
- }
-
-
- /***************************************************************************/
- int getfiles(void) /* get all the files */
- {
-
- int done;
- getdir;
- strcat(buffer,"\\*.*"); /* current dir and all the files */
- done = findfirst(buffer,&ffblk,0); /* get first file */
- delete_file(ffblk.ff_name); /* delete that */
-
- while (!done)
- {
- done = findnext(&ffblk); /* find next file */
- err = delete_file(ffblk.ff_name); /* delete that file */
- }
-
- return 0;
- }
-