user3885927
user3885927

Reputation: 3503

Find last update time of a directory (includes all levels of sub folders)

What is a good way to find out the last updated time of a directory? Note that this includes update to any levels of the subfolders as well. I know I can use os.path.getmtime or os.stat but they seem to work only if the immediate contents of the folder are changed. Do I need to recursively check for all subfolders and get the max modified time or is there a better way to do this?

Upvotes: 3

Views: 767

Answers (1)

Jason
Jason

Reputation: 3917

You can use os.walk...

m = max(map(lambda x: os.path.getmtime(x[0]), os.walk("directory")))

Upvotes: 4

Related Questions