| [reply] |
First, define what you mean by "60-day old directory." Do you mean the directory was created 60 days ago or the oldest file contained within it is 60 days old?
I believe that most O/S mark a directory as modified (change it's mod time) only if a file has been added or deleted (this includes moved), but not if a file has been changed, i.e., touching an existing file won't necessarily change the mod time on the including directory1.
The actual function you would is either rmdir or rmtree from the File::Path module. Unlink won't remove directories, unless "you are superuser and the -U flag is supplied to Perl." It also warns against using unlink to remove directories in all circumstances.
added in update1 …of course, these same comments apply to directories within the top level directory, and their sub-directories, and so forth. Recursion!
Information about American English usage here and here. Floating point issues? Please read this before posting. — emc
| [reply] |
| [reply] [d/l] [select] |
unix%> /usr/bin/find . -type d -mtime +60 -exec /bin/rm -rf {} \;
- replace "." with the directory you want to search below
- "-type d" says "directories"
- "-mtime +60" says "not modified in 60 days" (also consider "-atime" for "last accessed (aka "read") time" or "-ctime" for "change time", depending on how you measure "age".)
- "-exec" passes matching directory names to "/bin/rm -rf".
Edited: per moritz's suggestion, recommend "mtime" instead of "atime" although it's all up to you...
| [reply] [d/l] |
| [reply] |
| [reply] |
Well, in the bash shell I'd say something like:
find . -mtime -59 -type d -print | xargs rm -rf
(the argument may not be exactly right, do a man on find for the right args, and I'd also do whatever option xargs has to *not* execute if nothing comes down the pipe, but then this is a perl question, so ...)
Well, so in perl I'd do something dumb like run the 'find' command above (without the rm), fiddle with the output in any way I felt reasonable, then either use a perl-based 'rm -rf' or run another shell command.
Not very perl-ish, I'm afraid, and probably pushing the 'more than one way to do it' a bit too far, but if you wanted to perl-ize it more do a cpan lookup for a 'find' replacement (which I'm sure you could write or find - I mean, its just 'open directory', get its age, and recurse), and for a 'rm -rf' replacment).
Oh, goodness: there is a 'find' at http://search.cpan.org/perldoc?File::Find but it doesn't check the status. Perhaps you should check out 'find2perl', to which you give my above script (or something similar), and it will spit out the perl... see http://search.cpan.org/~nwclark/perl-5.8.8/x2p/find2perl.PL
| [reply] [d/l] |
This question is kind of OS specific. | [reply] |
I just threw last year's Yellow Pages in the bin. Maybe that'll work for you too. | [reply] |