请参阅以下代码。当我拨打get_files_by_most_recent
时,我会获得阈值为1秒的最新文件。
import os
class FileSystem:
@staticmethod
def get_files_by_most_recent(directory, threshold=1.0):
files = FileSystem.get_files(directory)
files.sort(key=lambda x: os.path.getmtime(os.path.join(directory, x)))
filtered = filter(lambda y: os.path.getmtime(os.path.join(directory, files[-1])) - os.path.getmtime(os.path.join(directory, y)) <= threshold, files)
return filtered
@staticmethod
def get_files(directory):
files = [f for f in os.listdir(directory) if os.path.isfile(os.path.join(directory, f))]
return files
现在我想要两种新方法:
我该怎么做?
以下是示例文件列表:
sceflh.jpg - 2014-08-23 05:07:46.100000000
rgxanx.jpg - 2014-08-23 05:07:45.900000000
byoiup.jpg - 2014-08-23 05:07:45.700000000
rrqgnh.jpg - 2014-08-23 05:07:45.500000000
sqthcv.jpg - 2014-08-23 05:07:40.320000000
ebrmvv.jpg - 2014-08-23 05:07:40.200000000
xzvsnt.jpg - 2014-08-24 08:12:01.110000000
ckiinz.jpg - 2014-08-24 08:12:01.100000000