Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options

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

by tye (Sage)
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        

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (12)
As of 2016-10-27 12:20 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (362 votes). Check out past polls.