首页 > 解决方案 > 如何获取子目录中所有文件的创建日期

问题描述

我有一个子目录中的文件路径列表。如何找到每个文件路径的创建日期?我使用下面的代码使用 Python 获取每个子目录中的所有文件:

def find(pattern, path):
    result = []
    for root, dirs, files in os.walk(path):
        for name in files:
            if fnmatch.fnmatch(name, pattern):
                result.append(os.path.join(root, name))
    return result

find(pattern, Path)

标签: pythonos.walk

解决方案


尝试以下功能之一:

os.path.getmtime(file_path)或者os.path.getctime(file_path)


推荐阅读