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)