基于时间的目录列表
如何根据时间戳列出目录中的文件?
os.listdir()
以任意顺序列出。
是否有内置函数可以根据时间戳列出?或按任何命令?
How to list the files in a directory based on timestamp?
os.listdir()
lists in arbitrary order.
Is there a build-in function to list based on timestamp? or by any order?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以对每个文件调用
stat()
并排序通过时间戳之一,也许通过使用返回文件时间戳的关键函数。You could call
stat()
on each of the files and sort by one of the timestamps, perhaps by using a key function that returns a file's timestamp.我的直接解决方案是,
根据 blueish 指出的重复帖子,这是一个糟糕的解决方案;为什么不好?
My immediate solution is,
As per the duplicate post pointed by bluish, this is a bad solution; why is it bad?