Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8659557
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:02:36+00:00 2026-06-12T16:02:36+00:00

all. I’m trying to write a script that checks the age of some files

  • 0

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!!!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:02:37+00:00Added an answer on June 12, 2026 at 4:02 pm

    It looks like you probably want to do something like this:

    for fn in os.listdir(path, f):
        fn = os.path.join(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 occurrence of appended files
        elif ctime < now - 10 * 86400: #checking for old file
            old_files.append(fn)
    if new_files:
        for fn in old_files:
            os.remove(fn)
    else:
        import sendmail
            sendmail.sendmail()
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

All, I have some script tags that are not working in Wordpress. If I
all. We're trying to get some intersect collisions working, but the problem experience is
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
All, I have a stored procedure on SQL Server 2005 that accepts an XML
All, We could really do with some advice from SVG gurus. WHAT WE HAVE:
All, My classpath has been set to the following folder: CLASSPATH = .;C:\Program Files\Java\jdk1.6.0_21\bin;C:\Program
All, I have a form with a MultiValueField that almost works. It uses a
All, I have a shell script on Mac OS X which uses the mdls
All - Need some insight into this issue. I have created a sample project
All, I currently have two projects that are under SourceSafe that I am unable

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.