导航

 
import os
def find_newest_file(path_file,filename=None):
    lists = os.listdir(path_file)
    if filename:
        lists_temp=[]
        for i in lists:
            if i.startswith(filename):
                lists_temp.append(i)

        lists=lists_temp
    lists.sort(key=lambda fn: os.path.getmtime(path_file +'\\'+fn))
    file_newest = os.path.join(path_file,lists[-1])

    return file_newest
if __name__ =='__main__':
    file_newest = find_newest_file(r'D:\\',filename='Python')
    print(file_newest)

  

posted on 2020-12-22 10:54  slqt  阅读(330)  评论(0编辑  收藏  举报