我正在製作一個程序,打印超過90天的所有文件夾在Python中。
這裏是我的代碼:python打印文件夾和子文件夾時,只需要在python的文件夾
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)
的問題是,這種打印的所有文件夾,但它也打印文件夾,我不需要的子文件夾。如何更改代碼以便它只打印文件夾?
對,在這裏按順序使用'next'而不是索引。 –