I would check that os.path.join(r,dir) is giving you the directory you think it is.
- japhy On Mon, Jan 24, 2011 at 12:25 PM, bsd...@gmail.com <bsd...@gmail.com> wrote: > Hi, hoping for some help here. I've been trying to write a python script > (complete newb) and have spent several days trying to get this right with no > success. > > I am trying to list timestamps in a directory and if they are older than x > amount of days delete the directories. It seems that in my for loop it is > only evaluating the last timestamp of the last directory and using that > timestamp to make the deletion decision. I realize that this script isn't > going to delete the directories with evaluate as true but I haven't been > able to get that far yet... > > > > ###########start script############## > ###Modules### > > import os > import time > > ###Global Variables### > > curr_t = time.time() > > days = 2629743 #2629743 is 30 days in epoch time. > > directory=os.path.join("/home", "userid", "python") > > > for r,d,f in os.walk(directory): > for dir in d: > timestamp = os.path.getmtime(os.path.join(r,dir)) ## It seems that > the below "if" statement is only comparing the timestamp of the last > directory that this variable lists. > print timestamp > if curr_t - days < timestamp: #### I am expecting > this statement to compare each timestamp of the "directory" variable and > print out if it should be deleted or not. > print "Your file will be deleted" > > else: > print "File will NOT be deleted..." > > > #######################end of script############################# > > > > Thank you for your time! > > _______________________________________________ > Tutor maillist - Tutor@python.org > To unsubscribe or change subscription options: > http://mail.python.org/mailman/listinfo/tutor > > _______________________________________________ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: http://mail.python.org/mailman/listinfo/tutor