python 一个文件夹最新文件复制到另外一个文件夹
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")
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库