找回密码
 立即注册
搜索
热搜: Excel discuz
查看: 1333|回复: 1

练习题-遍历所有Excel文件,移动到指定目录,并用创建日期重命名

[复制链接]

482

主题

7万

元宝

75万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
750849
发表于 2021-6-27 21:19:54 | 显示全部楼层 |阅读模式
  1. import os
  2. import datetime as dt
  3. if not os.path.exists('excel存放'):
  4.     os.mkdir('excel存放')
  5. for lujing,wenjianjia,wenjian in os.walk(os.getcwd()):
  6.     for file in os.scandir(lujing):
  7.         if file.name.endswith('xlsx'):
  8.             data1 = dt.datetime.fromtimestamp(file.stat().st_mtime)
  9.             newname = str(data1.year)+'-'+str(data1.month)+'-'+str(data1.day)+'-'+file.name
  10.             os.rename(lujing+'/'+file.name,'excel存放/'+newname)
复制代码



回复

使用道具 举报

482

主题

7万

元宝

75万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
750849
 楼主| 发表于 2021-6-27 21:20:09 | 显示全部楼层
2021-06-27_210042.png
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|五花八门论坛 ( 豫ICP备15031300号-3 )

GMT+8, 2024-4-25 07:49 , Processed in 0.131616 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表