[Tutor] Removing files based upon time stamps

Marc Tompkins marc.tompkins at gmail.com
Thu Jun 26 02:40:32 CEST 2008


On Wed, Jun 25, 2008 at 2:21 PM, chase pettet <chase.mp at gmail.com> wrote:


> import os, time, sys
> current = time.time()
> os.chdir("c:\BACKUPS\DEV1")
>
> for f in os.listdir('.'):
>   modtime = os.path.getmtime('.')
>   if modtime < current - 30 * 86400:
>     os.remove(f)
>

I'm not in a place where I can test anything at the moment, but the first
thing I always do in situations like this is to throw print/logging
statements all over the place so I can see what's going on.  (Slows it down
terribly, but it's temporary, right?)

I would do something like this:

for f in os.listdir('.'):
  modtime = os.path.getmtime('.')
  print f, modtime
  if modtime < current - 30 * 86400:
    print f, "  should be removed... is it?"
    os.remove(f)

At least it'll give you some idea of where things are going wrong.  As I
say, it's always the first thing I try.  It's rarely the last.

> This is my first list post.  Thanks for any help!
>

Welcome to the list!  Pull up a chair...

-- 
www.fsrtechnologies.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080625/75e85eb4/attachment.htm>


More information about the Tutor mailing list