我需要一个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\返回系列项目最后修改时间: 2019-09-23小时:\lance\预测最后修改时间: 2019-09-23小时:\lance\自定义价格文件最后修改时间:2019-09-23h:\lance\MBO和责任上次修改时间:209-09-23 h:\lance.vscode最后修改时间:209-09-23
发布于 2019-12-13 16:23:47
我想这就是你要找的
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)https://stackoverflow.com/questions/59323796
复制相似问题