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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T19:49:27+00:00 2026-05-11T19:49:27+00:00

Python’s os.path.getctime on the Mac (and under Unix in general) does not give the

  • 0

Python’s os.path.getctime on the Mac (and under Unix in general) does not give the date when a file was created but “the time of the last change” (according to the docs at least). On the other hand in the Finder I can see the real file creation time so this information is kept by HFS+.

Do you have any suggestions on how to obtain the file creation time on the Mac in a Python program?

  • 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-11T19:49:28+00:00Added an answer on May 11, 2026 at 7:49 pm

    Use the st_birthtime property on the result of a call to os.stat() (or fstat/lstat).

    def get_creation_time(path):
        return os.stat(path).st_birthtime
    

    You can convert the integer result to a datetime object using datetime.datetime.fromtimestamp().

    For some reason I don’t think this worked on Mac OS X when this answer was first written, but I could be mistaken, and it does work now, even with older versions of Python. The old answer is below for posterity.


    Using ctypes to access the system call stat64 (works with Python 2.5+):

    from ctypes import *
    
    class struct_timespec(Structure):
        _fields_ = [('tv_sec', c_long), ('tv_nsec', c_long)]
    
    class struct_stat64(Structure):
        _fields_ = [
            ('st_dev', c_int32),
            ('st_mode', c_uint16),
            ('st_nlink', c_uint16),
            ('st_ino', c_uint64),
            ('st_uid', c_uint32),
            ('st_gid', c_uint32), 
            ('st_rdev', c_int32),
            ('st_atimespec', struct_timespec),
            ('st_mtimespec', struct_timespec),
            ('st_ctimespec', struct_timespec),
            ('st_birthtimespec', struct_timespec),
            ('dont_care', c_uint64 * 8)
        ]
    
    libc = CDLL('libc.dylib') # or /usr/lib/libc.dylib
    stat64 = libc.stat64
    stat64.argtypes = [c_char_p, POINTER(struct_stat64)]
    
    def get_creation_time(path):
        buf = struct_stat64()
        rv = stat64(path, pointer(buf))
        if rv != 0:
            raise OSError("Couldn't stat file %r" % path)
        return buf.st_birthtimespec.tv_sec
    

    Using subprocess to call the stat utility:

    import subprocess
    
    def get_creation_time(path):
        p = subprocess.Popen(['stat', '-f%B', path],
            stdout=subprocess.PIPE, stderr=subprocess.PIPE)
        if p.wait():
            raise OSError(p.stderr.read().rstrip())
        else:
            return int(p.stdout.read())
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Python does not print traceback messages from exceptions raised in daemon threads. For example,
Python allows to call a static method not only from a class, but also
python manage.py dumpdata modelName > file.json . created an empty database for a user
Python does not provide built-in support for multi-dimensional arrays. I need to develop an
Python 2.6 Using Python string.replace() seems not working for UTF-16-LE file. I think of
Python 3 really complicated the whole file reading process, when you have a binary
Python is on version 2.7.3, but when i try to upgrade python through pip
Python beginner here. I have a text file that is sorted into columns: fields
Python is so dynamic that it's not always clear what's going on in a
Python's arbitrary precision decimals are lovely, but I can't seem to find a way

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.