www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/04/05/18:15:38

Message-ID: <38EB8F2C.3F23FD4@cyberoptics.com>
From: Eric Rudd <rudd AT cyberoptics DOT com>
Organization: CyberOptics
X-Mailer: Mozilla 4.72 [en] (Win95; U)
X-Accept-Language: en
MIME-Version: 1.0
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Best way to implement DELTREE
References: <8ccfq7$v1q$1 AT newsg1 DOT svr DOT pol DOT co DOT uk> <38EA1EA7 DOT 6A8E81BE AT is DOT elta DOT co DOT il> <8ce9g4$nth$1 AT newsg4 DOT svr DOT pol DOT co DOT uk>
Lines: 29
Date: Wed, 05 Apr 2000 14:08:28 -0500
NNTP-Posting-Host: 38.196.93.9
X-Trace: client 954961709 38.196.93.9 (Wed, 05 Apr 2000 15:08:29 EDT)
NNTP-Posting-Date: Wed, 05 Apr 2000 15:08:29 EDT
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Ben Davis wrote:

> Eli Zaretskii wrote in message <38EA1EA7 DOT 6A8E81BE AT is DOT elta DOT co DOT il>...
> >You can use the directory-traversal functions provided in the library.
>
> I've considered that, but they both check directories before they check the
> subdirectories. If I'm deleting, I need to empty a directory before I remove
> it.

I wrote a deltree program using findfirst/findnext a long time ago (before DOS
even had a DELTREE), but it's too much of a mess to make public -- I think you
could simplify things a lot with ftw, anyway.  However, you don't need to make
any assumptions about the order in which the files and subdirectories are
reported.  The strategy is simple, regardless of the routines used for the
traversal: after descending into the directory to be removed, if you encounter a
file, delete it; if you encounter a directory, descend into it; if the current
directory is empty, ascend back out of it and remove it.  Eventually, the
program will dig its way to the very bottom, possibly deleting some files along
the way; with no more directories to enter, it must eventually start removing
files and working its way back up the tree.  When you ascend out of the
specified directory, remove it and stop.

I would highly recommend testing routines like this with dummy files on a spare
floppy.  It will slow down execution a bit, but at least you won't lose your
entire hard drive because of a faulty stopping criterion.

-Eric Rudd
rudd AT cyberoptics DOT com

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019