Python 3.x Python程序列出所有修改了日期的文件夹

Python 3.x Python程序列出所有修改了日期的文件夹,python-3.x,Python 3.x,我需要一个Python程序来列出所有修改了日期的文件夹。当我运行它时,所有的修改日期都是相同的。我做错了什么 以下是我正在使用的代码: import os, time, stat path = 'h:\\lance\\' folders = [] r=root, d=directories, f = files for r, d, f in os.walk(path): for folder in d: modTimesinceEpoc = os.path.get

我需要一个Python程序来列出所有修改了日期的文件夹。当我运行它时,所有的修改日期都是相同的。我做错了什么

以下是我正在使用的代码:

import os, time, stat

path = 'h:\\lance\\'

folders = []

r=root, d=directories, f = files
for r, d, f in os.walk(path):
    for folder in d:

        modTimesinceEpoc = os.path.getctime(path)
        modificationTime = time.strftime('%Y-%m-%d', time.localtime(modTimesinceEpoc))

        folders.append(os.path.join(r, folder))

[0:5] just grabs the first 5 folders, helpful if the total amount of folders is large

for f in folders [0:5]:
    print(f, "Last Modified Time : ", modificationTime)
输出:

h:\lance\Return系列项目上次修改时间:2019-09-23 h:\lance\Forecast Pro上次修改时间:2019-09-23 h:\lance\Custom Price Files上次修改时间:2019-09-23 h:\lance\MBO和职责上次修改时间:2019-09-23 h:\lance.vscode上次修改时间:2019-09-23


我想这就是你要找的

import os, time, stat

path = 'h:\\lance\\'

folders = []

# r=root, d=directories, f = files
for r, d, f in os.walk(path):
    for folder in d:
        location = os.path.join(r, folder)
        modTimesinceEpoc = os.path.getctime(location)
        modificationTime = time.strftime('%Y-%m-%d', time.localtime(modTimesinceEpoc))
        folders.append((location, modificationTime))

# [0:5] just grabs the first 5 folders, helpful if the total amount of folders is large

for f in folders[:5]:
    print(f)