Links
Comment on page

Get last file modified from directy

Tags: #python #os #library #file #modified #directory
Author: Florent Ravenel​
Last update: 2023-04-12 (Created: 2023-02-23)
Description: This notebook will show how to get the last file modified from a directory using the os library.
References:

Input

Import libraries

import os

Setup Variables

# Set the directory path
directory_path = "./"

Model

Get last file modified

# Get the list of files in the directory
files_list = os.listdir(directory_path)
# Get the last file modified
last_file_modified = max(files_list, key=os.path.getmtime)

Output

Display result

# Print the last file modified
print(f"The last file modified is {last_file_modified}")