Reputation: 117
I want to compare two files from two different folders based on when they were created.
#!/usr/bin/env python
import os, time, datetime
f1 = "/home/source/file1.py"
f2 = "/home/backup3/file1.py"
os.path.getatime(f1)
print time.ctime(os.path.getatime(f1))
print time.ctime(os.path.getatime(f2))
The files were created at different times, but I get the same time and date as output; why? I would like to compare the timestamps of these two files so that whenever source/file1.py
is changed we make a new copy of it in backup3
.
Upvotes: 1
Views: 2860
Reputation: 78
You probably want to use the os.path.getmtime(path)
or the os.path.getctime(path)
methods for getting the last modification or creation timestamp, respectively.
From the docs, os.path.getatime(path)
returns the time of last access of path. Ref: https://docs.python.org/3/library/os.path.html#os.path.getatime
Upvotes: 3