asbach
Goto Top

Dateiattribute insb Creation und Modification Date in Python setzen

Hallo!
Ich möchte in Python ähnlich wie mit touch -r die Eigentschaften eines Files auf einen anderen übertragen.
Mit os.stat kann ich mir die Eigenschaften des Quellfiles holen.
Wie setze ich diese Eigenschaften auf das Zielfile?

Content-Key: 313161

Url: https://administrator.de/contentid/313161

Ausgedruckt am: 28.03.2024 um 08:03 Uhr

Mitglied: 129813
129813 20.08.2016 aktualisiert um 17:48:28 Uhr
Goto Top
Hi,
if you are working under Linux, there is no "file creation time" face-wink
http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes ...

But you can modify file access and modification times
#!/usr/bin/python
import os
# get source file attributes
source = os.stat('sourcefile.txt')  
# Set file dates of target file to that from source file
os.utime('targetfile.txt',(source.st_atime,source.st_mtime))  
os.utime()

Regards