This program uses the os.walk()
function to iterate through all files and directories in the specified root directory. For each file, it uses the os.path.getmtime()
function to get the modification time, and compares it to the specified date using a simple if
statement. If the modification time is later than the specified date, the full path of the file is printed. os module provides a portable way of using operating system dependent functionality
Here is an example Python program that gets all the files with their full paths that were modified after a specific date:
import os
import datetime
# specify the directory to search in
root_dir = '/path/to/directory/to/search'
# specify the date to compare against MMMM,YY,DD format
date = datetime.datetime(2023, 02, 14)
# iterate through all files and directories in the root directory
for dirpath, dirnames, filenames in os.walk(root_dir):
for filename in filenames:
# construct the full path of the file
file_path = os.path.join(dirpath, filename)
# get the modification time of the file
mtime = datetime.datetime.fromtimestamp(os.path.getmtime(file_path))
# check if the modification time is after the specified date
if mtime > date:
print(file_path)
os.path.getmtime(path): Cross-platform way to get file modification time in Python. It returns the timestamp of when the file was last modified.
os.path.getctime(‘file_path’): To get file creation time but only on windows.
os.stat(path).st_birthtime: To get file creation time on Mac and some Unix based systems.