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 6934325
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:56:43+00:00 2026-05-27T11:56:43+00:00

I have built a script that generates files daily and names them by the

  • 0

I have built a script that generates files daily and names them by the date that they are generated. However, I then need to delete these files after 1 month, and have found it to be a bit confusing. I believe that the following will work, but I would like to know if Python has a built in feature that allows for this a bit more Pythonicly and elegently.

Note that this code handles files that are at the end of a month with more days than the following month by deleting all files from last month when it reaches the last day of this month.

if today.month != 1:
    if today.day == days_in_month[today.month] and days_in_month[today.month] < days_in_month[today.month - 1]:
        for x in range(days_in_month[today.month],days_in_month[today.month-1]+1):
            date = date(today.year,today.month-1,x)

            fname = str(date)+".stub"
            remove(fname)
else:
    date = date(today.year-1,12,x)

    fname = str(date)+".stub"
    remove(fname)
  • 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-05-27T11:56:44+00:00Added an answer on May 27, 2026 at 11:56 am

    Take a look at Python’s datetime module, it has some classes that should simplify this a lot. You should be able to create a datetime.datetime object from your file name using datetime.datetime.strptime(), and another for the current time using datetime.datetime.now(). You can then subtract one from the other to get a datetime.timedelta object that you can use to figure out the difference between the dates.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a Python script that uses built-in modules but also imports a number
I have an ant build script that needs to pull files down from a
I have some automatically generated Ant build scripts that I need to use to
I have a utility build script that gets called from a variety of project-specific
I have a build script and as part of that script it copies a
I have a nightly build DOS batch script that invokes devenv.exe to build a
I have a custom script step in my build process that zips the executable.
I have a Java project that I build using an Ant script. I am
I have built an object in Javascript on the Google Apps Script engine and
I have a problem. I built a script to make a request to an

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.