all.
I’m trying to write a script that checks the age of some files in a folder, and deletes the old files if new files have been created. If new files were not created, then it does not delete the old files and it sends me an email telling me that no new files were created.
I use the OS module ctime to check the age of files, and I’m using an external script “sendmail” to handle the emailing.
As it works now, it correctly determines old and new files, and then deletes old files, but it does not correctly make the decision about whether or not to call sendmail. Let me show you:
for fn in os.listdir(path, f)
fn = os.path.jion(path, f)
ctime = os.stat(fn).st_ctime
if ctime > now - 1 * 86400: #this is a new file
new_files.append(fn)
countit = new_files.count(fn) #counting the occurence of appended files
if new_Files.count(fn) > countit: #checks the list
import sendmail
sendmail
elif ctime < now - 10 * 86400: #checking for old file
old_files.append(fn)
if new_files:
for fn in old_files:
os.remove(fn)
So, can I get some help on this? I’m really stuck. Should I be using an elif statement to check my list, like so:
if ctime > now - 1 * 86400:
new_files.append(fn)
elif:
import sendmail
sendmail
Is that a proper way to write that? Is there a correct way to write this decision? Is my whole script wrong?
EDIT – Sorry if I’m being whiny, I’ve been working on this for some time, and it’s very frustrating. I appreciate whatever help you can give!!!
It looks like you probably want to do something like this: