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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T15:53:52+00:00 2026-06-11T15:53:52+00:00

The issue I am running into is part of using os.stat on a path

  • 0

The issue I am running into is part of using os.stat on a path (Take C:\myfile1.txt for example). When I run os.stat on this file and take the 9th element in the resulting list I get the modified time in the form of some numbers (ex. 1348167977).

NOTE: I’m not sure how these numbers are calculated.

When I create C:\myfile1.txt it has some number like the example above. If I create another file C:\myfile2.txt, it gets a new number representing the modified time which is higher than C:\myfile1.txt (this is like I would expect). I also have a third file C:\myfile3.txt which is created last.

The issue comes if I copy C:\myfile2.txt and overwrite C:\myfile3.txt with the resulting copy file, the modified time as shown by os.stat on the new C:\myfile3.txt is less than C:\myfile1.txt. Why does this happen? The modified time for C:\myfile3.txt should be the highest of all or at least equal to C:\myfile2.txt.

Thanks for you answers, I hope I explained this well enough.

EDIT:

Here’s some sample code to test what I describe. Sometimes it works sometimes the numbers are all the same if you rerun it at a different time. I think I just don’t fully understand the MTIME that I’m outputting.

import os
import shutil
import time

myfile1 = open("C:\\myfile1.txt", 'wt')
myfile1.close()
time.sleep(10)
myfile2 = open("C:\\myfile2.txt", 'wt')
myfile2.close()
time.sleep(10)
myfile2 = open("C:\\myfile3.txt", 'wt')
myfile2.close()

shutil.copyfile("C:\\myfile2.txt", "C:\\myfile3.txt")

modified_time_first = (os.stat("C:\\myfile1.txt")[9])
modified_time_second = (os.stat("C:\\myfile2.txt")[9])
modified_time_third = (os.stat("C:\\myfile3.txt")[9])

print "The first files modified time is: "
print modified_time_first
print ""

print "The second files modified time is: " 
print modified_time_second
print ""

print "The third files modified time is: " 
print modified_time_third
print ""
  • 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-11T15:53:53+00:00Added an answer on June 11, 2026 at 3:53 pm

    The number you see is a UNIX timestamp, and represents the number of seconds since the epoch, the 1st of January 1970. You could use datetime.datetime.fromtimestamp() to turn that into a python datetime object for example:

    >>> import datetime
    >>> datetime.datetime.fromtimestamp(1348167977)
    datetime.datetime(2012, 9, 20, 21, 6, 17)
    

    Note that os.stat() returns a named tuple; you can access the properties on that tuple by name too:

    >>> import os
    >>> os.stat('test.txt').st_mtime
    1348169795.0
    

    See the os.stat() documentation for all the attributes that are available.

    You, on the other hand, accessed the st_ctime value instead; python tuples and list indexes start at 0, so the 9th element is index 8. You accessed index 10, the creation time of the files.

    If all you need is the modified time of a file, you can also use os.path.getmtime() as a convenient shortcut:

    >>> os.path.getmtime('test.txt')
    1348169795.0
    >>> datetime.datetime.fromtimestamp(os.path.getmtime('test.txt'))
    datetime.datetime(2012, 9, 20, 21, 36, 35)
    

    When copying a file, it’s properties such as last-modification timestamp are usually included, thus the modified time of the newly copied file could easily change, both backwards and forwards. The same applies to the creation time.

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

Sidebar

Related Questions

I'm running into a character encoding issue when I load a dropdown using jQuery
Attempting to run a MIB based SNMP script and I running into an issue.
Using Spring 3.0.x, I'm running into an issue where a Bean init-method is running,
running into a little issue, can't quite figure it out. I'm using jQuery on
I'm working on creating a self updating application and one issue I'm running into
I was running into the following issue: // $data contains some image data $gm
I'm running into a very odd issue with a validator that is meant to
I'm running into an issue that's arising from the fact that one has to
I'm running into an issue where my deployment loops through Recycling. From Visual Studio:
I am running into a very strange issue and I am convinced it is

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.