• 移动并重命名工作簿
 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. .NET8 Hello World!

    ​ 使用ASP.NET Core Web Application模板创建的Empty项目如下: ​ 这是一个最简单的Web项目,运行起来会在根路径响应Hello World! 2.1.1 Progra ...

  2. WXS 模块

    https://developers.weixin.qq.com/miniprogram/dev/framework/view/wxs/01wxs-module.html 2.1.概述 WXS(Wei ...

  3. redux中集成immutable.js

    安装redux-immutable redux中利用combineReducers来合并reducer并初始化state,redux自带的combineReducers只支持state是原生js形式的 ...

  4. 利用nodejs的require.context来实现不用写impor导入组件

    先给你们看下目录结构 stuendt和teacharts还有util是同级 主要是componentRegister.js文件 function changStr(str) { return str. ...

  5. Mysql中innodb的B+tree能存储多少数据?

    引言 InnoDB一棵3层B+树可以存放多少行数据?这个问题的简单回答是:约2千万.为什么是这么多呢?因为这是可以算出来的,要搞清楚这个问题,我们先从InnoDB索引数据结构.数据组织方式说起. 在计 ...

  6. 5分钟带你了解RabbitMQ的(普通/镜像)集群

    前言 让我们深入探讨RabbitMQ的集群配置,了解各种集群模式的利弊.本次讨论的重点是帮助您快速理解RabbitMQ集群的运作方式,以及选择最适合您需求的模式.好的,话不多说.在RabbitMQ中, ...

  7. 18.9k star!一个高性能的嵌入式分析型数据库,主要用于数据分析和数据处理任务。

    大家好,今天给大家分享的是一个开源的面向列的关系数据库管理系统(RDBMS). DuckDB是一个嵌入式的分析型数据库,它提供了高性能的数据分析和数据处理能力.DuckDB的设计目标是为数据科学家.分 ...

  8. 查看es结构,es _search查询基础语法

    查看es结构,es _search查询基础语法 http://xx.xx.xx.xx:9200/ ES地址 car_info/_search POST {} POST { "query&qu ...

  9. Shell依次输出1,2,3...

    个人觉得,Shell没有其他语言方便,同样是脚本语言,我更倾向于Python. Shell怎么输出1,2,3,4类似的递增数列呢? #!/bin/bash i=0 while [ $i -le 100 ...

  10. 采集modbus设备数据转wincc项目案例

    1         文档说明 1.   网关设置采集Modbus设备数据 2.   把采集的数据转成profinet协议转发给wincc. 2         VFBOX网关工作原理 VFBOX网关是 ...