Skip to content

Latest commit

 

History

History
52 lines (31 loc) · 1.79 KB

Python_Get_last_file_modified_from_directy.md

File metadata and controls

52 lines (31 loc) · 1.79 KB



Template request | Bug report | Generate Data Product

Tags: #python #os #library #file #modified #directory

Author: Florent Ravenel

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}")