AI办公自动化:用Kimi批量在Excel文件名中加入日期

工作任务:在一个文件夹中所有的Excel文件后面加上一个日期

在Kimi中输入提示词:

你是一个Python编程专家,写一个Python脚本,具体步骤如下:

打开文件夹:F:\AI自媒体内容\AI行业数据分析\投融资

读取里面所有的xlsx文件的主文件名;

在主文件名后面加上"20240528",重命名文件;

注意:每一步都要输出相关信息到屏幕上;

运行程序,返回错误信息:

Traceback (most recent call last):

File "d:\Python\Exceladddate.py", line 25, in <module>

new_file = os.path.join(folder_path, new_file)

NameError: name 'new_file' is not defined

发送给kimi,让其修正:

修改后的源代码:

import os

设置文件夹路径

folder_path = r"F:\AI自媒体内容\AI行业数据分析\投融资"

确保文件夹路径存在

if not os.path.exists(folder_path):

print(f"The directory {folder_path} does not exist.")

else:

列出文件夹中所有的文件

files = os.listdir(folder_path)

过滤出所有的xlsx文件

xlsx_files = file for file in files if file.endswith('.xlsx')

遍历xlsx文件列表

for file in xlsx_files:

获取不带扩展名的文件名

base_name = os.path.splitext(file)0

新文件名

new_name = f"{base_name}20240528.xlsx"

构造完整的文件路径

old_file = os.path.join(folder_path, file)

new_file = os.path.join(folder_path, new_name) # 确保 new_name 已经定义

try:

重命名文件

os.rename(old_file, new_file)

print(f"Renamed '{file}' to '{new_name}'")

except Exception as e:

print(f"Error renaming file '{file}': {e}")

print("File renaming process completed.")

相关推荐
Lorin 洛林9 小时前
OpenClaw:跳出聊天框,拥有自主行动力的 AI 智能体
人工智能
rain_sxr9 小时前
大规模数据可视化渲染:D3 与 ECharts 的管线优化实战
人工智能
大海变好AI9 小时前
AIGC分层推理落地能否串联多工具完成自动化闭环
人工智能·python·自动化·aigc
Cosolar10 小时前
AI Agent 架构原理详解:从一次提问到任务完成的完整闭环
人工智能·后端·架构
小白说大模型10 小时前
从向量嵌入到复杂 Agent:LLM、LangChain、LangGraph 完整科普
java·开发语言·人工智能·gpt·深度学习·langchain
协享科技10 小时前
2026 年 AI 表格工具怎么选:ChatGPT、原生 Copilot/Gemini 与公式助手
人工智能·chatgpt·excel·copilot
geo搜搜果数据10 小时前
实测AI搜索GEO监测工具:对比DeepSeek与豆包品牌排名差异
人工智能·langchain·embedding·搜搜果
王莎莎10 小时前
MCP 解决的是工具接入,科研 Agent 还缺的是科学证据接口标准化
前端·人工智能
码农小白AI10 小时前
工业设备验收迈入智能审核新时代:AI报告审核通审Agent版 IACheck打造检测报告质量管控新引擎
大数据·人工智能
摸鱼师moko10 小时前
AI 来了之后,我的心流状态去哪了
人工智能·程序员