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?
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?
Please also mark the comments that contributed to the solution of the article
Content-Key: 313161
Url: https://administrator.de/contentid/313161
Printed on: April 24, 2024 at 22:04 o'clock
1 Comment
Hi,
if you are working under Linux, there is no "file creation time"
http://www.cyberciti.biz/tips/understanding-unixlinux-filesystem-inodes ...
But you can modify file access and modification times
os.utime()
Regards
if you are working under Linux, there is no "file creation time"
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))
Regards