Created
February 11, 2025 12:17
-
-
Save plu5/d3f35c585ce008b96d03d30cf49d897b to your computer and use it in GitHub Desktop.
NTFS-3G creation date of a file in Python
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import subprocess | |
| from datetime import datetime, timezone | |
| def get_ntfs3g_file_creation_date(path): | |
| # type: (str) -> str | |
| c = subprocess.run([ | |
| 'getfattr', '--only-values', '--name=system.ntfs_crtime', path | |
| ], capture_output=True) | |
| # Convert getfattr output's little-endian bytes to int, and convert | |
| # Microsoft time to Unix epoch time | |
| epoch = int.from_bytes(c.stdout, 'little')/10000000-11644473600 | |
| # From there you can pass it in to datetime or any other date library. | |
| # Here I convert it to a UTC ISO 8601 str timestamp. | |
| return datetime.fromtimestamp(epoch, timezone.utc).isoformat() | |
| # Example usage: | |
| print(get_ntfs3g_file_creation_date('/path/to/file/on/ntfs')) | |
| # -> 2016-02-13T08:10:59.525232+00:00 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment