Nov-08-2021, 09:07 PM
Greetings!
I need to find yesterday's modified directories.
but a PC I'm running the code on has Python 2.7 and I cannot use pathlib...
The code I have has a problem (see the error below), I can't get a Path from the string..
"AttributeError: 'str' object has no attribute 'stat'"
I Googled for an answer for about an hour or so but could not find a solution...
Here is the code I got so far:
I need to find yesterday's modified directories.
but a PC I'm running the code on has Python 2.7 and I cannot use pathlib...
The code I have has a problem (see the error below), I can't get a Path from the string..
"AttributeError: 'str' object has no attribute 'stat'"
I Googled for an answer for about an hour or so but could not find a solution...
Here is the code I got so far:
import os.path
import datetime as dt
tz ='C:\\01'
for dr_name in os.listdir(tz):
dr_path = os.path.join(tz, dr_name)
print(type(dr_path)) ## <-- it is alredy a string not Path
if os.path.isdir(dr_path):
print("Directory path name:", dr_path)
print(type(dr_path))
np = os.path.normpath(dr_path)
print(type(np)) ## <-- Still string
yesterday = dt.datetime.now().date() - dt.timedelta(days=1)
if yesterday == dt.datetime.fromtimestamp(np.stat().st_mtime).date():
print(f" Directory modified yesterday -> {np}")Thank you!
