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)

  

相关文章:

  • 2022-01-21
  • 2022-03-01
  • 2022-12-23
  • 2021-09-24
  • 2022-12-23
  • 2021-11-18
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-11-03
  • 2021-12-03
  • 2021-10-11
  • 2021-10-09
  • 2022-01-02
  • 2021-11-07
  • 2022-01-15
相关资源
相似解决方案