Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

Re: Removing all directories recursively except one

by sundialsvc4 (Abbot)
on Aug 07, 2014 at 02:50 UTC ( #1096540=note: print w/replies, xml ) Need Help??

in reply to Removing all directories recursively except one

A few thought-questions and food-for-thought bits here:

(1)   Might this be an “XY Problem?”   Might the thing that you are “ultimately trying to accomplish,” in fact be a well-known problem that has been addressed already ... say, by a command such as logrotate?   “Writing a brand-new program,” in whatever language it might be, is a pretty-cool thing to have done, unless (heh, heh ...) at the end you discover that someone else, a dozen years ago or more, already did it infinitely-better.   (Ouch!)   Frankly, this requirement smells a lot like just such a situation.

(1a)   I say this from “red-faced experience.”   ’Nuff said ...

(1b)   To make this assessment fairly, you must “drag yourself, kicking-and-screaming, away from How,” and force yourself to stare at What.

(2)   If you do find that you need to monkey with a directory-structure in this way, let me strongly advise you to write your code so that it does the job in two distinct stages.   First, it should scan the target directory to gather-up a list of contained directories ... remembering (Ouch! #2 ...) to ignore "." and "..".   Fully complete the scan, then process your list.   In other words, do not attempt to manipulate the directory structure during the scan.

  • Comment on Re: Removing all directories recursively except one

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096540]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (6)
As of 2018-05-23 23:12 GMT
Find Nodes?
    Voting Booth?