Hello,
I can't figure out how to run "dir" in Windows. At this point, I get "Output:ERROR:None":
Thank you.
--
Edit: As a work-around, don't bother with Windows's dir command:
I can't figure out how to run "dir" in Windows. At this point, I get "Output:ERROR:None":
CMD = "dir /AD /OD c:\\".rstrip()
CMD = r"dir /AD /OD c:".rstrip()
CMD = r"dir /AD /OD c:"
CMD = "dir /AD /OD c:"
print(CMD)
p = subprocess.run((['cmd.exe', '/c', 'dir', CMD]), text=True, stdout=subprocess.PIPE, creationflags=subprocess.CREATE_NO_WINDOW)
if p.returncode != 0:
output = f"ERROR:{p.stderr}"
else:
output = f"OK: {p.stdout}"
blah = input(f"Output:{output}")Does someone know?Thank you.
--
Edit: As a work-around, don't bother with Windows's dir command:
import time, os DIR=r"c:\temp" dirs = [s for s in os.listdir(DIR) if os.path.isdir(os.path.join(DIR, s))] for dir in dirs: print(dir, time.ctime(os.path.getmtime(dir)))
import time
from datetime import datetime, timezone
from pathlib import Path
paths = [subdir for subdir in Path(DIR).iterdir() if subdir.is_dir()]
paths = sorted(paths, key=os.path.getmtime)
for path in paths:
stat_result = path.stat()
modified = datetime.fromtimestamp(stat_result.st_mtime, tz=timezone.utc).strftime('%Y-%m-%d')
print(f"{path} {modified}")
