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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T03:57:46+00:00 2026-05-28T03:57:46+00:00

Do files opened like file(foo.txt) have any info about file modification time? Basically I

  • 0

Do files opened like file("foo.txt") have any info about file modification time?

Basically I want to know if the file has been modified or replaced since a certain time, but if the file is replaced between checking modification time and opening the file, then you have inaccurate information.

How can I be sure?

Thanks.

UPDATE

@rubayeet: Thanks for the answer (+1), I actually didn’t think of that. But… What to do if the modification time has changed? Perhaps I reload the file again. But what if it changes that time? If the file is being touched regularly I could end up in a loop forever! What I really want is a way to just get an open file handle and a modification time to go with it, without a potential infinite loop.

PS The answer you gave was actually plenty good enough for my purposes as the file won’t be changed regularly, its general interest on my part now.

UPDATE 2

Thinking the previous update through (and experimenting a little) I realize that simply knowing the file modification time at the point the file was opened is not so much use as if the file is modified while reading you can have some or all of the modified data in the stuff you read in, so you’d have to open and read/process the whole file, then check mtime again (as per @rubayeet’s answer) to see if you may have stale data.

  • 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-28T03:57:47+00:00Added an answer on May 28, 2026 at 3:57 am
    import os
    filepath = '/path/to/file'
    modifytime1 = os.path.getmtime(filepath)
    fp = open(filepath)
    modifytime2 = os.path.getmtime(filepath)
    if modifytime1 != modifytime2:
        print "File modified after opening"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In my project regression settings, output file have statement like diff between foo.txt and
I have a longish list of files opened in vim that looks like this:
I would like to know who is locking a file (win32). I know about
When sockets are created or files are opened/created in C, is the file descriptor
On a typical OS how many files can i have opened at once using
just think that when I opened my file then when I want to write
I have opened a file with blast results and printed out the hits in
Files with a .SQL extension when opened in Visual Studio 2008 have T-SQL syntax
I would like to draw an image opened with the HTML5 File API on
I created a software which edits some XML files. When a file is opened

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.