简体   繁体   English

如何查找未在Python中最新修改的最新创建文件

[英]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.

相关问题 如何使用Python按名称搜索文件,查找最新修改的文​​件,查找下一个文件并重复步骤? - How to use Python to search for file by name, find the latest modified, find next file and repeat steps? 如何通过python只获取在S3位置创建/修改的最新文件/文件 - How can I get only the latest file/files created/modified on S3 location through python 如何使用Python在目录中查找最新文件 - How to find the latest file in a directory with Python Iglob 查找最新创建的,而不是最新修改的 - Iglob finding latest created, not latest modified 如何打印文件的最新修改部分? - How to print the latest modified portion of a file? Python:如何选择最新创建的文件(将Keras检查点上传到GCS) - Python: How to select the latest created file (Uploading Keras Checkpoints to GCS) 如何使用python获取最新创建的文件名而不是文件夹名? - How to get the latest created file name and not the folder name using python? 如何从 CSV 文件中查找最早和最晚日期 [Python] - How to find earliest and latest dates from a CSV File [Python] 如何使用Boto Python从S3获取最新文件的最后修改日期? - How to get last modified date of latest file from S3 with Boto Python? 使用python,regex和glob查找最新文件 - Find the latest file using python, regex and glob
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM