python - 如何编辑多个excel表的名称?
问题描述
我有一组文件夹名称作为播放器的名称。在文件夹中,我有一个名为 gw 的 excel 表或两个名为 gw 和 history 的 excel 表。
现在,我希望将所有 gw excel 工作表的名称更改为它们所属文件夹的名称。
这是一个示例:我有一个文件夹名称“Aaron Cresswell”。在文件夹中,我有两个 excel 表“gw”和“history”。我希望将“gw”excel 表的名称更改为“Aaron Cresswell”。
我不能手动操作,因为有 439 个这样的播放器文件夹。
任何帮助将不胜感激。谢谢。
解决方案
你可以在 Python 中这样做。
import os
base_path = r'C:\Users\Documents\<snip>'
for directory in os.listdir(base_path):
os.rename(
os.path.join(base_path, directory, 'gw.xlsx'),
os.path.join(base_path, directory, '{}.xlsx'.format(directory))
)
wherebase_path
是包含播放器名称目录的文件夹的路径。
推荐阅读
- matplotlib - python 3数字在ubuntu上冻结
- django - 如何在 django 模型中查询特定的外部记录
- machine-learning - Inception V3 图像分类
- ssas - 动态测量测量 (MDX)
- c# - Serilog 排除了自定义记录器提供程序
- c# - MongoDb 命令获取更多 Mongo C# 驱动程序失败
- android - 房间持久性库@Query 不工作
- julia - 从离线安装加载 Ipopt 时 Julia 出错
- namespaces - PhpStorm 使用不正确的命名空间
- php - 在 wordpress 中动态更改样式表中的 url 路径