recursive directory deletion

recursive directory deletion

Post by Brian E. Gall » Fri, 25 Oct 1991 22:07:37



Does anybody out there have a method for deleting entire directory trees
WITHOUT multiple steps?  I have to evaluate software, and so I often
need to remove entire directory structures, and multilevel trees can be
a pain.

                                  -Brian

You drop the bomb -more-
It goes off... -more-
-------------------------------------------------------------------------
|  Have your mail Daemon message my mail Daemon and we'll do lunch!     |
-------------------------------------------------------------------------
|  Ghostriders...HOOOOOOO!                                              |
-------------------------------------------------------------------------

 
 
 

recursive directory deletion

Post by Tom Reingo » Sun, 27 Oct 1991 04:15:47



$ Does anybody out there have a method for deleting entire directory trees
$ WITHOUT multiple steps?  I have to evaluate software, and so I often
$ need to remove entire directory structures, and multilevel trees can be
$ a pain.

The most convenient way is to use a program that does this.  The best
example that comes to mind is "rm" which comes with the MKS toolkit.
It's a clone of the UNIX "rm" command.  To remove a directory
recursively, type "rm -rf dirname".  Use with extreme care, of course.

A program like this is not hard to write.  I would bet you can get one
just like it for free on the Usenet archives.
--
        Tom Reingold

        "Warning: Do not drive with Auto-Shade in place.  Remove
        from windshield before starting ignition."

 
 
 

recursive directory deletion

Post by Sen Fai L » Mon, 28 Oct 1991 14:23:16




Quote:>Does anybody out there have a method for deleting entire directory trees
>WITHOUT multiple steps?  I have to evaluate software, and so I often
>need to remove entire directory structures, and multilevel trees can be
>a pain.

NCD RMTREE <directory>
 ^
 |
Norton CD from Norton Utilities

Stephen

 
 
 

recursive directory deletion

Post by Timo Sal » Mon, 28 Oct 1991 16:26:39



>The most convenient way is to use a program that does this.  The best
>example that comes to mind is "rm" which comes with the MKS toolkit.
>It's a clone of the UNIX "rm" command.  To remove a directory
:
>A program like this is not hard to write.  I would bet you can get one
>just like it for free on the Usenet archives.

Exactly.  Besides the Unix-like alternatives there are also
"genuine" MsDos alternatives.  Try eg
  garbo.uwasa.fi:/pc/dirutil/pdel42.zip

"If you do not know how to go about getting this package you are
welcome to email me for the prerecorded garbo.uwasa.fi instructions,


mirror information.  North American users are advised first to
search for this file on SIMTEL20 or its mirror wuarchive.wustl.edu.
Respectively, Oceanian users are referred to rana.cc.deakin.oz.au."

...................................................................
Prof. Timo Salmi
Moderating at garbo.uwasa.fi anonymous ftp archives 128.214.87.1
School of Business Studies, University of Vaasa, SF-65101, Finland

 
 
 

recursive directory deletion

Post by Hi Ho Silv » Tue, 29 Oct 1991 02:37:26



$Does anybody out there have a method for deleting entire directory trees
$WITHOUT multiple steps?  I have to evaluate software, and so I often
$need to remove entire directory structures, and multilevel trees can be
$a pain.

   Yeah, it's easy.  Write a program to do it.

   If you'd rather get your hands on one that's already written, send

clone of the Unix rm command; it has -r (recursive), -i (interactive),
-f (force) and -v (verbose) switches and should do what you're looking
for.  I'll even see if I can find the doc file I wrote for it a couple
of years ago.
--
.--------------------------------------.      ...!uunet!xrtll!silver
|Silver, perpetually searching for SNTF|----------------------------
`--------------------------------------'a vaguely phallic .signature

 
 
 

recursive directory deletion

Post by tj » Wed, 30 Oct 1991 02:26:19


In article <Id1gKNW00WBK81B...@andrew.cmu.edu>, bg...@andrew.cmu.edu (Brian E. Gallew) writes:

>Does anybody out there have a method for deleting entire directory trees
>WITHOUT multiple steps?  I have to evaluate software, and so I often
>need to remove entire directory structures, and multilevel trees can be
>a pain.

 Here is the thing you want. The compiler I use is TURBO C v2.0.
 And BE CAREFUL !! This program is for big boys only!
 Best of luck
     Tom
--------------------------  cut here --------------------------------------
/* DELALL.C      ------------------------------------                      */
/*                                                                         */
/* Deletes subdirectory trees                             -- 20-Mar-91 --  */
/*                                                                         */
/*                     by T.J. Kazmierski                                  */
/*          Department of Electronics and Computer Science                 */
/*                 University of Southampton                               */
/*               SOUTHAMPTON, Hants SO9 5NH, U.K.                          */
/*          tel. +44 703 593520  fax +44 703 593045                        */
/*          e-mail  t...@ecs.soton.ac.uk                                    */
/*                                                                         */
/* Copyright Note:                                                         */
/*             Feel free to use or copy the source;                        */
/*             a donation of #0.50 to my Holsten Pils fund                 */
/*             will be very much appreciated                               */
/*                                                                         */
/* usage:                                                                  */
/*         go to a subdirectory and type DELALL                            */
/*         The entire subdirectory tree with all the nested                */
/*          subdirectories and files will be deleted                       */

#include <dir.h>
#include <conio.h>
#include <ctype.h>
#include <dos.h>
#include <sys/stat.h>
#include <stdio.h>

int chdir(const char *path);
char *getcwd(char *buf, int buflen);

/* recursive delete */
void deldel(char *cwd,int level);

#define BUFLEN 80
int files,subs;
main(int argc,char *argv[]) {
 char cwd[BUFLEN];
 int i;

 if (argc < 2)
  getcwd(cwd,BUFLEN);
 else
 {
  strcpy(cwd,argv[1]);
  if(chdir(cwd) < 0)
  {
   strcat(cwd,"\\");
   if(chdir(cwd)<0)
   {
    printf("Path %s does not specify an existing directory\n",cwd);
    exit();
   };
  };
 };

 printf("Do you want to delete all the files in the directory:\n%s\n"
        "including all the nested subdirectories and their files? (y/n)\n",
         cwd);
 if(tolower(getch()) != 'y')
  {
   printf("Aborted\n");
   exit();
  };

 files = subs = 0;
 deldel(cwd,0); /* recursively delete */
 printf("%d files and %d subdirectories deleted\n",files,subs);

}

/** main() ----------------------------------------------------------------- */

void deldel(char *cwd,int level) { /* delete all files, scan tree recursively*/
 struct ffblk block, block_next;
 int done,attr,i;
 char attr_text[10],buf[80];

 /* delete local files */
 strcpy(buf,cwd);
 i = strlen(buf) - 1;
 if(buf[i] != '\\')
  strcat(buf,"\\");
 strcat(buf,"*.*");
 attr =  FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_ARCH ;
 done = findfirst(buf,&block,attr);
 while(!done)
 {
  strcpy(buf,cwd);
  i = strlen(buf) - 1;
  if(buf[i] != '\\')
   strcat(buf,"\\");
  strcat(buf,block.ff_name);

  if(block.ff_attrib & (FA_RDONLY | FA_HIDDEN | FA_SYSTEM) )
  {
    printf("File %s is marked as:\n",buf);
    if (block.ff_attrib & FA_RDONLY)
     printf("READ ONLY   ");
    if (block.ff_attrib & FA_HIDDEN)
     printf("HIDDEN   ");
    if (block.ff_attrib & FA_SYSTEM)
     printf("SYSTEM   ");
    printf("\nDo you still want to delete it (y/n)?\n");

    if(tolower(getch()) == 'y')
    {
     chmod(buf,S_IREAD | S_IWRITE);
     printf("Deleting %s\n",buf);
     if(remove(buf))
      printf("File %s NOT DELETED\n",buf);
     else
      files++;
    };
  }
  else
  {
   printf("Deleting %s\n",buf);
     if(remove(buf))
      printf("File %s NOT DELETED\n",buf);
     else
      files++;
  };

  done = findnext(&block);
 };  /* while */

 /* deleting in subdirectories */
 strcpy(buf,cwd);
 i = strlen(buf) - 1;
 if(buf[i] != '\\')
  strcat(buf,"\\");
 strcat(buf,"*");
 attr =  FA_RDONLY | FA_HIDDEN | FA_SYSTEM | FA_ARCH | FA_DIREC;
 done = findfirst(buf,&block,attr);
 while(!done)
 {
  strcpy(buf,cwd);
  i = strlen(buf) - 1;
  if(buf[i] != '\\')
   strcat(buf,"\\");
  strcat(buf,block.ff_name);

  if( (block.ff_attrib & FA_DIREC)
     &&   strcmp(block.ff_name,".")  != 0
     &&   strcmp(block.ff_name,"..") != 0 )
  {
    /* carry on recursion */
     deldel(buf,level+1);
     /* remove empty directory */
     if(block.ff_attrib & (FA_RDONLY | FA_HIDDEN | FA_SYSTEM) )
     {
       printf("File %s is marked as:\n",buf);
       if (block.ff_attrib & FA_RDONLY)
        printf("READ ONLY   ");
       if (block.ff_attrib & FA_HIDDEN)
        printf("HIDDEN   ");
       if (block.ff_attrib & FA_SYSTEM)
        printf("SYSTEM   ");
       printf("\nDo you still want to delete it (y/n)?\n");

       if(tolower(getch()) == 'y')
       {
        chmod(buf,S_IREAD | S_IWRITE);
        printf("Deleting subdirectory %s\n",buf);
        if(rmdir(buf))
         printf("Subdirectory %s  NOT DELETED\n",buf);
        else
         subs++;
       };
     }
     else
     {
      printf("Deleting subdirectory %s\n",buf);
      if(rmdir(buf))
        printf("Subdirectory %s  NOT DELETED\n",buf);
      else
       subs++;
     };
  }; /* if */

  done = findnext(&block);
 };  /* while */

}

/** deldel() --------------------------------------------------------------- */
/*****************************************************************************/
 
 
 

recursive directory deletion

Post by smil.. » Wed, 30 Oct 1991 07:15:46



Quote:> Does anybody out there have a method for deleting entire directory trees
> WITHOUT multiple steps?  I have to evaluate software, and so I often
> need to remove entire directory structures, and multilevel trees can be
> a pain.

You might try out the PCMagazine utility called PRUNE.  It can be
found in the directory <msdos.pcmag> in either SIMTEL20 or one of
the mirror sites, or in many BBSs.  The file it is in is called
VOL09N12.ZIP.  Another companion set of files to get is DIRMAG2.ZIP
in the same directory.  PRUNE will lop off a whole limb of your
directory tree, move it to a different branch, or to another disk!
I use it on many small computers at work.  It can run the DIRMAGIC
file manager (although it will have to be renamed DR.COM to be
called) and another handy file comparison program DIRMATCH (found
in <msdos.pcmag> as DIRMAT20.ZIP.  Try this series, you will be
pleased.