Building on what you already provided and what you already know with os.path.getmtime()
, you can use the time.time()
function to get the current time. You can substract the modified time from the current time to get the time difference in seconds. I use (60*60*24)
to get this to days.
The following code does each of those steps:
import glob
import os
import time
files = glob.glob("C:/Folder/*.csv")
modified_files = list()
current_time = time.time()
for csv_file in files:
time_delta = current_time - os.path.getmtime(csv_file)
time_delta_days = time_delta / (60 * 60 * 24)
if time_delta_days < 60:
modified_files.append(csv_file)
print(modified_files)
Edit:
A more pythonic way to write this might be:
import glob
import os
import time
def test_modified(filename):
delta = time.time() - os.path.getmtime(filename)
delta = delta / (60*60*24)
if delta < 60:
return True
return False
mfiles = [mfile for mfile in glob.glob("C:/Folder/*.csv") if test_modified(mfile)]
print(mfiles)