Jürgen Paul
Jürgen Paul

Reputation: 15037

Folder modification time including the files inside it?

currently what I do is:

import os

dir = '/var/www/site1.com'
modTime = os.path.getmtime(dir)

But the modification time is not as recent as the modification time of the most recent file modified inside that folder. Is there a way to get the mtime of that directory/folder with respect to the files/folder inside it?

Upvotes: 0

Views: 109

Answers (1)

Martijn Pieters
Martijn Pieters

Reputation: 1125398

Not without looking at the mtime value for each and every file in that folder.

You can use max() on the getmtime value for each entry in the folder:

modTime = max([os.path.getmtime(os.path.join(dir, p)) for p in os.listdir(dir)])

Upvotes: 2

Related Questions