I am making a program that prints all the folders over 90 days in python.
Here is my code:
import os
from datetime import date
from Tkinter import *
import Tkinter, Tkconstants, tkFileDialog
old_dirs = []
today = date.today()
home1 = os.path.join(os.environ["HOMEPATH"], "Desktop")
desktop = os.path.join(os.path.join(os.environ['USERPROFILE']), 'Desktop')
root = Tk()
root.withdraw()
path = tkFileDialog.askdirectory(initialdir=desktop, title="Select folder to
scan from: ")
path = path.encode('utf-8')
for root, dirs, files in os.walk(path):
for name in dirs:
filedate = date.fromtimestamp(os.path.getmtime(os.path.join(root, name)))
if (today - filedate).days > 90:
print name
old_dirs.append(name)
The problem is that this prints all folders, but it also prints the sub folders of the folders, which I don't need. How can I change the code so that it only prints the folders?