how do I delete empty directories on my D:\ drive let's say.... I'm writing in Python and for some reason, my code doesn't work. I can't figure out the problem
Thanks for the help... code:
import os
path = 'D:\\'
dire = []
for file in os.listdir(path):
print(file)
dire.append(file)
try:
for file in dire:
new_path = 'D:\{0}'.format(file+"\\")
if os.listdir(new_path) == []:
os.rmdir(file)
print(file+" has been deleted")
else:
print("directory "+file+" is not empty")
except (FileNotFoundError, NotADirectoryError):
print(file+" could not be located, or opened...")
dire.remove(file)