asbach

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?
Auf Facebook teilen
Auf X (Twitter) teilen
Auf Reddit teilen
Auf Linkedin teilen

Content-ID: 313161

Url: https://administrator.de/forum/dateiattribute-insb-creation-und-modification-date-in-python-setzen-313161.html

Ausgedruckt am: 30.05.2025 um 10:05 Uhr

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