[英]How to find latest created file not latest modified in Python
I want to find which is the latest created file but not latest modified. 我想找到哪个是最新创建的文件,而不是最新修改的文件。 I saw a couple of answers but not dealing with my problem.
我看到了几个答案,但没有解决我的问题。 So modified file should not affect the result.
因此,修改后的文件不应影响结果。 This is the code I have so far.
这是我到目前为止的代码。 But
但
import glob
import os
list_of_files = glob.glob('/PDF Parsing/*')
# list_of_files = os.listdir('PDF Parsing')
print(list_of_files)
latest_file = max(list_of_files, key=os.path.getctime)
print (latest_file)
This is not possible on most unix systems. 在大多数Unix系统上这是不可能的。 The creation time is not stored.
创建时间未保存。 See this answer
看到这个答案
Exception is ext4, see this page ext4是例外,请参阅此页面
You can see if your fs supports it by issuing 您可以通过发出以下命令查看fs是否支持它
stat -c %W $FILE
-> 0 if unknown stat -c %W $FILE
> 0(如果未知)
You might be able to achieve this using some control versioning system, which will store the creation time. 您可能可以使用某些控件版本控制系统来实现此目的,该系统将存储创建时间。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.