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

Re: Can't remove directory-Permission denied (-M)

by tye (Cardinal)
on Oct 22, 2012 at 16:50 UTC ( #1000383=note: print w/ replies, xml ) Need Help??


in reply to Can't remove directory-Permission denied

kennethk was right-on when noting that deleting the "." directory is usually a bad idea (and the source of your error message).

However, for the above code to try to delete ".", I believe that that would mean that D:\TestDelete\Test was declared to-be-deleted by your code (especially for $File::Find::name to be '.' -- my testing shows $_ being '.' when File::Find gets all the way to the top of the directory tree being searched and $File::Find::name never being '.', just FYI).

That being the case means that the whole use of File::Find is a waste and you could just have done rmtree("D:/TestDelete/Test").

That leads me to consider the logic behind your code more critically. Deleting directories where the modification time of the directory is more than 2 but less than 4 days in the past is certainly a bit strange.

Beyond that, you should realize that creating or deleting a file in the foo/bar directory will have no impact on the foo directory's modification time. So you may need to use more sophisticated tests if you want to avoid removing a directory full of files made 2-or-fewer or 4-or-more days ago just because some parent or grand-parent directory was modified during that time window. And, of course, modifying a file has no impact on the containing directory's modification time.

But you give no real hint at the motivation for the rather strange use of -M so I can't suggest any specific improvements.

- tye        


Comment on Re: Can't remove directory-Permission denied (-M)
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (14)
As of 2014-08-22 13:30 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (158 votes), past polls