[ALUG] Scripting help: deleting old directories
cl at isbd.net
Wed Dec 22 12:58:40 GMT 2010
On Wed, Dec 22, 2010 at 11:18:40AM +0000, Mark Rogers wrote:
> Is there a simple way to locate directories which only contains
> files older than a certain date and then remove the directories?
> I can find old files easily enough, but if a directory has more than
> one file in it and one of the files is new, then I need to not touch
> the entire directory. It's only where all the files are old that I
> want it removed.
I think that's just about the level of 'difficultness' where I move from
a bash script to python. IMHO Python lends itself very well to jobs
like this. Python has a ready made function that 'walks' a directory
tree like find does so all you need is a bit of logic to check if all
the files in a directory are older than x and, if so, delete the directory.
More information about the main