How to get the date of source content created in windows using python?

Question:

I have a file with the following properties where I can retrieve created and modified dates by using pathlib (st_ctime, st_mtime) easily.

General Property Tab

But I want to get the date displayed in the Details section of the same property tab, shown in the red box:

Details Property Tab

How can I do that in python preferably by using inbuilt packages?

Asked By: Javid Shiriyev

||

Answers:

note that this only works for new style xlsx files

>>> from xml.etree import ElementTree
>>> import zipfile
>>> xls_zip = zipfile.ZipFile("example.xlsx")
>>> xml_contents = xls_zip.read("docProps/core.xml")
>>> et = ElementTree.fromstring(xml_contents)
>>> created = et.find('dcterms:created',{"dcterms":"http://purl.org/dc/terms/"}).text
>>> modified = et.find('dcterms:modified',{"dcterms":"http://purl.org/dc/terms/"}).text
>>> print("C:",created)
C: 2020-04-24T17:46:16Z
>>> print("M:",modified)
M: 2020-04-24T17:46:16Z

this just opens the xlsx file as a zipfile (you can rename the file to end with zip and just open it with the windows explorer unzip)

then it gets the "file" that contains the metadataxml

then it extracts (from the proper namespace) the keys that correspond to those 2 values

Answered By: Joran Beasley
Categories: questions Tags: , ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.