Hello,
I mistyped a "dir" command in Windows, and now all the subdirectories have the (wrong) same date :-/
As a way to get a more realistic date, I'd like to 1) loop through each subdirectory, 2) find the oldest file at the root in each, and 3) use that to set the subdirectory's date… but Google didn't help: Is there a command to set a directory's date?
Thank you.
I mistyped a "dir" command in Windows, and now all the subdirectories have the (wrong) same date :-/
As a way to get a more realistic date, I'd like to 1) loop through each subdirectory, 2) find the oldest file at the root in each, and 3) use that to set the subdirectory's date… but Google didn't help: Is there a command to set a directory's date?
Thank you.
import os ROOT = r"c:\html" os.chdir(ROOT) dirs = [f for f in os.listdir() if os.path.isdir(f)] for dir in dirs: os.chdir(rf"{ROOT}\{dir}") files = sorted(os.listdir(os.getcwd()), key=os.path.getmtime) oldest = files[0] atime = os.stat(oldest).st_atime #TODO how to use "oldest" to set the parent folder's time?