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

Ask A Question

Stats

  • Questions 124k
  • Answers 124k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Give a look to this book: patterns & practices Application… May 12, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer It's been a while since I've used Prototype, but on… May 12, 2026 at 1:16 am
  • Editorial Team
    Editorial Team added an answer Hi, I was wondering why MYSQL uses a single equals… May 12, 2026 at 1:16 am

Related Questions

Python has this wonderful way of handling string substitutions using dictionaries: >>> 'The %(site)s
Python works on multiple platforms and can be used for desktop and web applications,
Python uses the reference count method to handle object life time. So an object
Python gives us the ability to create 'private' methods and variables within a class
Python's convention is that variables are created by first assignment, and trying to read

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.