python - 按创建日期的顺序打印目录的内容

标签 python

有人用 python 完成过这个吗?

这是我目前所拥有的...

if os.path.isdir(options.map_file_directory):
    searchedfile = glob.glob("*.map")
    files = sorted( searchedfile, key = lambda file: os.path.getctime(file))

    for i in files:
        print("{} - {}".format(i, time.ctime(os.path.getctime(i))) )

最佳答案

解决了我自己的问题。与我“四处游荡”的方式有关

if os.path.isdir(options.map_file_directory):
    print ("this is a test 4")
    searchedfile = glob.glob(r'{}\*.map'.format(options.map_file_directory))
    files = sorted( searchedfile, key = lambda file: os.path.getctime(file))

    for i in files:
        print("{} - {}".format(i, time.ctime(os.path.getctime(i))) )

关于python - 按创建日期的顺序打印目录的内容,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32464533/

相关文章:

python - 有没有办法遍历两个字典中的所有键并更改所有重复的项目,以便字典的项目全部不同

python - 为 scrapy 安装 python - 符号链接(symbolic link)和权限问题

python - emacs 交互式 python shell 显示没有反馈

python - SQLite 查询性能、Transpose、Melt 和 Pandas

python - 如何在 Python 中制作多键击功能

python - 将文本区域输入转换为分段 HTML

Python,数据帧: Duplicating rows according to the number of items in a list and ranking the resulted rows

python - 无法访问已部署版本的 AppStats

python - 覆盖模块类型定义

python - 枚举具有相同前缀的列