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

Printed on: April 24, 2024 at 22:04 o'clock

Mitglied: 129813
129813 Aug 20, 2016 updated at 15:48:28 (UTC)
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