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")
复制代码

 

posted @   dafengchui  阅读(161)  评论(1编辑  收藏  举报
相关博文:
阅读排行:
· 物流快递公司核心技术能力-地址解析分单基础技术分享
· .NET 10首个预览版发布:重大改进与新特性概览!
· 单线程的Redis速度为什么快?
· 展开说说关于C#中ORM框架的用法!
· Pantheons:用 TypeScript 打造主流大模型对话的一站式集成库
点击右上角即可分享
微信分享提示