1 # -*- coding: utf-8 -*- 2 import os 3 import shutil 4 5 6 def listdir(path, list_name): # 传入存储的list 7 for file in os.listdir(path): 8 file_path = os.path.join(path, file) 9 if os.path.isdir(file_path): 10 listdir(file_path, list_name) 11 else: 12 list_name.append((file_path, os.path.getctime(file_path))) 13 14 15 def newestfile(target_list): 16 newest_file = target_list[0] 17 for i in range(len(target_list)): 18 if i < (len(target_list) - 1) and newest_file[1] < target_list[i + 1][1]: 19 newest_file = target_list[i + 1] 20 else: 21 continue 22 print('newest file is', newest_file) 23 return newest_file 24 25 def set(k): 26 default_path = r'C:\Users\Asus\Downloads' 27 down_file = r'C:\Users\Asus\Desktop\ie客户平台数据对比\网上充值明细.xlsx' 28 list = [] #暂估价项目疑问-3.31.xls 29 listdir(default_path, list) 30 new_file = newestfile(list) 31 print('from:', new_file[0]) 32 print('to:', shutil.copy(new_file[0], down_file)) 33 print(k) 34 35 36 if __name__ == '__main__': 37 set("das")