|XP is just a number|
Re: Can't remove directory-Permission denied (-M)by tye (Cardinal)
|on Oct 22, 2012 at 16:50 UTC||Need Help??|
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.