Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Removing all directories recursively except one

by sundialsvc4 (Monsignor)
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?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1096540]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (12)
As of 2014-09-19 05:28 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (129 votes), past polls