When managing a large number of files divided into folders, if the update date of the latest file directly under the folder is set, it is useful when sorting on Windows, so I wrote it. If you make one, you may not be at a loss when you look at the classification folder.
import os
from pathlib import Path
#Find a directory based on the current path and apply the latest update date of files under that directory.
p = Path("./")
for d in list(p.glob('*')):
if d.is_dir :
filedts = []
for filep in list(d.glob('*')):
filedts.append((filep.stat()).st_mtime)
filedts.sort(reverse=True)
if len(filedts) > 0 :
print(d.name + ' ' + str(filedts[0]))
os.utime(d,(filedts[0],filedts[0]))
I am using it with NTFS mounted on Linux. I am using st_mtime, but please read it as atime or ctime as appropriate depending on the file system.
The Path object can be used for anything and is convenient. Let's use it steadily.
Recommended Posts