Jun-30-2021, 11:18 PM
Greetings!
I'm trying to use pathlib.Path to identify empty Subdirectories (and delete them).
For some reason, my code cannot identify if a Subdir is empty.
3 of 4 Subdirectories have a small text file inside but all 3 identified as Empty.
I'm trying to use pathlib.Path to identify empty Subdirectories (and delete them).
For some reason, my code cannot identify if a Subdir is empty.
3 of 4 Subdirectories have a small text file inside but all 3 identified as Empty.
mydir = 'C:\\02'
for fel in pathlib.Path(mydir).iterdir():
if fel.is_dir():
print(f"{fel} is a Directory")
p = pathlib.Path(fel)
stat = p.stat().st_size
print(f" Size = {stat}")I tried adding IF but it did not do anygood...mydir = 'C:\\02'
for fel in pathlib.Path(mydir).iterdir():
if fel.is_dir():
print(f"{fel} is a Directory")
p = pathlib.Path(fel)
stat = p.stat().st_size
print(f" Size = {stat}")
if stat == 0 :
print(f" Empty Dir --> {stat}") Thank you.
