I am trying to write a python script backing up a folder, and keeping it for x days.
I use
shutil.copytree(source, finaldest)
My problem is, the timestamp from the original files persists, meaning the folders will be deleted if the files within is older than x days. What i want is the timestamp to be the time of backup, regardless of the original creation date
After doing the copytree(), you can then modify the timestamps on the files like so:
import os
for dirpath, _, filenames in os.walk(finaldest):
os.utime(dirpath, None)
for file in filenames:
os.utime(os.path.join(dirpath, file), None)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With