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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T02:05:01+00:00 2026-06-07T02:05:01+00:00

My django app parses some files uploaded by the user.It is possible that the

  • 0

My django app parses some files uploaded by the user.It is possible that the file uploaded by the user may remain in the server for a long time ,without it being parsed by the app.This can increase in size if a lot of users upload a lot of files.

I need to delete those files not recently parsed by the app -say not accessed for last 24 hours.I tried like this

import os
import time

dirname = MEDIA_ROOT+my_folder
filenames = os.listdir(dirname)
filenames = [os.path.join(dirname,filename) for filename in filenames]
for filename in filenames:
    last_access = os.stat(filename).st_atime #secs since epoch
    rtime = time.asctime(time.localtime(last_access))
    print filename+'----'+rtime

This shows the last accessed times for each file..But I am not sure how I can test if the file access time was within the last 24 hours..Can somebody help me out?

  • 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-07T02:05:03+00:00Added an answer on June 7, 2026 at 2:05 am

    Check out time.time(). It will allow you to access the current timestamp, in utc time. You can then subtract the current stamp from the file timestamp and see if it’s greater than 24*60*60.

    http://docs.python.org/library/time.html#time.time

    Also, keep in mind that a lot of the time, a Linux filesystem is mounted with noatime, meaning the st_atime variable might not be populated. You should probably use st_mtime, just to be safe, unless you’re 100% sure the filesystem will always be mounted with atimes recorded.

    Here’s what should be a working example, I haven’t debugged though.

    import os
    import time
    
    dirname = MEDIA_ROOT+my_folder
    filenames = os.listdir(dirname)
    filenames = [os.path.join(dirname,filename) for filename in filenames]
    for filename in filenames:
        last_access = os.stat(filename).st_mtime #secs since epoch
        timediff = time.gmtime() - last_access
        print filename+'----'+timediff
        if timediff > 24*60*60:
            print 'older than a day'
            # do your thing
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A Django app that I am working has an Event model. An Event may
I have a Django app where multiple teams upload content that will be parsed.
In my django app, I have a view which accomplishes file upload.The core snippet
I'm running a Django app on Apache + mod_python. When I make some changes
I have a Django app that gets it's data completely from an external source
I am developping a django app on Windows, SQLite and the django dev server
I have a Django app that use a django-tagging. I need to port this
I have a Django app that uses MySQL as a backend. I'm having difficulties
I have a django app that has / at the end of every URL
I'm writing a Django app that uses celery. So far I've been running on

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.