美文网首页
Python os获取文件根据时间排序

Python os获取文件根据时间排序

作者: 深吸一口气 | 来源:发表于2021-06-25 11:48 被阅读0次
    • os
    • lambda
    • sorted
    def sorted_file(file_path):
      dir_list = os.listdir(file_path)
      # os.path.getmtime() 函数是获取文件最后修改时间
      # os.path.getctime() 函数是获取文件最后创建时间
      # 通过对 sorted 添加参数reverse,控制降序、升序
      file_list = sorted(dir_list,key=lambda x: os.path.getmtime(os.path.join(file_path, x)))
      return file_list
    

    相关文章

      网友评论

          本文标题:Python os获取文件根据时间排序

          本文链接:https://www.haomeiwen.com/subject/svanyltx.html