• 移动并重命名工作簿
 1 from pathlib import Path  # 导入pathlib模块的path类
2 import time
3
4 # Press the green button in the gutter to run the script.
5 if __name__ == '__main__':
6 data = time.strftime('%y-%m-%d %H:%M:%S')
7
8 old_file_path = Path('D:\\demo\\python\\test_excel\\file_from\\test.xlsx')        # 这里的Path,等价于os.path,join();参考第10行代码
9 new_file_path = Path('D:\\demo\\python\\test_excel\\file_to\\test_rename.xlsx')
10 # test_path = Path('D:', 'demo', 'python', 'test_excel', 'file_from', 'test.xlsx')
11 old_file_path.rename(new_file_path)                               # 剪切并重命名
12
13 if new_file_path.is_file():
14 print(f'{data}:{old_file_path} rename successed')
  • 解析工作簿的路径信息
 1 from pathlib import Path  # 导入pathlib模块的path类
2 import time
3
4 # Press the green button in the gutter to run the script.
5 if __name__ == '__main__':
6 data = time.strftime('%y-%m-%d %H:%M:%S')
7 file_path = Path('D:\\demo\\python\\test_excel\\file_to\\test_rename.xlsx')
8 # 解析工作簿的路径信息
9 path = file_path.parent
10 # 打印文件所在路径
11 print(f'文件路劲----:{path}')
12 file_name = file_path.name
13 # 打印文件名字
14 print(f'文件名为----:{file_name}')
15 suffix = file_path.suffix
16 # 打印文件后缀名
17 print(f'文件后缀名为----:{suffix}')
  • 提取文件夹内所有工作簿的文件名
 1 from pathlib import Path  # 导入pathlib模块的path类
2
3 # Press the green button in the gutter to run the script.
4 if __name__ == '__main__':
5 folder_path = Path('D:\\demo\\python\\test_excel\\file_to')
6 file_list = folder_path.glob('*.xlsx')
7 print(f'file_list----:{file_list}')
8 lists = []
9 for test in file_list:
10 file_name = test.name
11 lists.append(file_name)
12 print(f'lists----:{lists}')

随机推荐

  1. VisioForge.DotNet.Core.UI.WPF WPF摄像头 UVC 显示 支持 .net core

    Sample applications available at https://github.com/visioforge/.Net-SDK-s-samples . Please add Visio ...

  2. 分享下最近基于Avalonia UI和MAUI写跨平台时间管理工具的体验

    起因 几个月前,我在寻找一款时间管理软件,类似番茄时钟的工具,但是希望可以自定义时间. 需要自定义的场景 做雅思阅读,3篇文件需要严格控制时间分配,需要一个灵活的计时器 定期提醒,每30分钟需要喝水或 ...

  3. 面试必会 --> MyBatis篇

    什么是MyBatis Mybatis是一个半ORM(对象关系映射)框架,它内部封装了JDBC,开发时只需要关注SQL语句本身,不需要花费精力去处理加载驱动.创建连接.创建statement等繁杂的过程 ...

  4. The model backing the 'MainDbContext' context has changed since the database was created. Consider using Code First Migrations to update the database (http://go.microsoft.com/fwlink/?LinkId=238269).

    The model backing the 'MainDbContext' context has changed since the database was created. Consider u ...

  5. java 日期 时间

    方法一(线程不安全, 不建议使用)private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss" ...

  6. echarts柱状图横(x)轴文字显示不全,一招解决

    柱状图底部X轴文字过长时,将会出现文字显示不全的问题,这是echarts为了美观默认的设置 现在我们把文章倾斜旋转点角度即可全部显示 以下是代码 scale() { var chartDom = do ...

  7. 13-nginx

    关于nginx nginx是提供http服务的中间件. 这里推荐学习nginx的博客:朱双印的博客 安装 nginx的版本 主线版本(Mainline version) #最新版,不稳定 稳定版本(S ...

  8. Nginx+Fail2ban 实现同一ip在一分钟内连续三次请求同一接口并响应成功时进行封禁

    1. 安装 Fail2Ban 和 Nginx 如果尚未安装 Fail2Ban 和 Nginx,可以使用以下命令进行安装: # CentOS默认的仓库中可能不包含Nginx,所以需要添加EPEL(Ext ...

  9. Python 使用Matplotlib绘制可拖动的折线

    Python 使用Matplotlib绘制可拖动的折线 效果图:  可以拖曲线上的点调整, 也可以拖旁边的sliderbar调整. 代码如下: import matplotlib.animation ...

  10. libevent之bufferevents

    目录 Bufferevents:概念和基础知识 Bufferevents 和 evbuffers 回调和水印 延迟回调 缓冲区事件的选项标志 使用基于套接字的缓冲区事件 创建基于套接字的缓冲区事件 在 ...