- Trending Categories
- Data Structure
- Operating System
- C Programming
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to get file creation & modification date/times in Python?
To get the creation time of a file, you can use the os.path.getctime(file_path) on windows. On UNIX systems, you cant use the same function as it returns the last time that the file's attributes or content were changed. To get the creation time on UNIX based systems, use the st_birthtime attribute of the stat tuple.
On Windows −
>>> import os >>> print os.path.getctime('my_file') 1505928271.0689342
It gives the time in the number of seconds since the epoch. For UNIX systems,
import os stat = os.stat(path_to_file) try: print(stat.st_birthtime) except AttributeError: # Probably on Linux. No easy way to get creation dates here, # so we'll settle for when its content was last modified. print(stat.st_mtime)
This will give the output −
For getting the modification time for a file, you can use the os.path.getmtime(path). It is supported cross-platform.
>>> import os >>> print os.path.getmtime('my_file') 1505928275.3081832
- How to get creation and modification date/time of a file using Python?
- How to set creation and modification date/time of a file using Python?
- How to get the creation date of a MySQL table?
- How do you get a directory listing sorted by creation date in Python?
- Get the creation time of a file in C#
- How do I get the creation date of a MySQL table?
- How to find and sort files based on modification date and time in linux
- How to get current date and time in Python?
- How to get formatted date and time in Python?
- How can I the date of creation and updation of tables in MySQL?
- MySQL query to display databases sorted by creation date?
- Creation of .ASM file using a text editor
- How to get current time and date in C++?
- How to get specific nodes in xml file in Python?