m0_75004425 2022-11-08 10:56 采纳率: 50%
浏览 26
已结题

os.rename(os.path.join( , ),os.path.join( , )+'.pdf')批量修改文件名。出现了参数错误,如何解决?

os.rename(os.path.join( , ),os.path.join( , )+'.pdf')批量修改文件名。出现了参数错误

问题详细如下:
X[WinError 87] 参数错误。: 'C:\Users\shinelon\.spyder-py3\111111\ERL-00-9.pdf' -> 'C:\Users\shinelon\.spyder-py3\111111\9Global Data Plane: A Widely Distributed Storage and Communication Infrastructure.pdf'

#我的目的是想用txt文本里面写好的东西改文件名
#这是我的代码

import os
#含我们要用的文件名的列表
with open(r"11.txt","r",encoding="utf-8") as f:
    liness=[]
    for i in f:
        b = i.strip()
        liness.append(b)
    #liness.rstrip()
    print(liness)
paths = r"C:\Users\shinelon\.spyder-py3\111111"     

# 待修改文件夹内文件名列表
fileList = os.listdir(paths) 
#将列表名按末尾的数字排列
def list_sort(x : str):
    if '.' in x:
        # 将文件名字用_进行分割
        x = x.rpartition('-')[2]
        # 将x用.进行分割,最后拿到数字
        x = int(x.split('.')[0])
    else:
        x = 0
    return int(x)
    # 排序前
print(fileList)
# 进行排序
fileList.sort(key=list_sort)        
# print(type(fileList))
# 输出文件夹中包含的文件

# print("修改前:" + str(fileList))
b=0
for a in fileList:
    os.rename(os.path.join(paths,a),os.path.join(paths,liness[b])+'.pdf')
    b+=1

#以下是执行结果
['10Metal: A Metadata-Hiding File Sharing System', '11Novel Computing Paradigms using Oscillators', '12Deep-learning-based Machine Understanding of Sketches: Recognizing and Generating Sketches with Deep Neural Network', '13A Fully Integrated Electronic-Photonic Platform for Label\x02Free Biosensing', '14Explainable and Advisable Learning for Self-driving Vehicles', '15Design of a sub-Hz Resolution Fully Digital RF Frequency Synthesizer', '16Low Noise Integrated CMOS Receiver Front-End', '17Reinforcement Learning for Robotic Assembly with Force Control', '18Analysis of Factors and Interventions Relating to Student Performance in CS1 and CS2', '19Building XP process metrics for project-based software engineering courses', '20Geometric Sampling Theory, Triangulations, and Robust Machine Learning']

['EECS-2020-11.pdf', 'EECS-2020-12.pdf', 'EECS-2020-13.pdf', 'EECS-2020-15.pdf', 'EECS-2020-16.pdf', 'EECS-2020-17.pdf']
Traceback (most recent call last):

  File "C:\Users\shinelon\AppData\Local\Temp\ipykernel_6036\1984612430.py", line 36, in <module>
    os.rename(os.path.join(paths,a),os.path.join(paths,liness[b])+'.pdf')

OSError: [WinError 87] 参数错误。: 'C:\\Users\\shinelon\\.spyder-py3\\11111\\EECS-2020-11.pdf' -> 'C:\\Users\\shinelon\\.spyder-py3\\11111\\10Metal: A Metadata-Hiding File Sharing System.pdf'


```python



```

  • 写回答

4条回答 默认 最新

  • honestman_ 2022-11-08 10:59
    关注

    应该是路径里面包含点导致的,试试把点去了:

    img

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

问题事件

  • 系统已结题 11月16日
  • 已采纳回答 11月8日
  • 创建了问题 11月8日

悬赏问题

  • ¥15 Attention is all you need 的代码运行
  • ¥15 一个服务器已经有一个系统了如果用usb再装一个系统,原来的系统会被覆盖掉吗
  • ¥15 使用esm_msa1_t12_100M_UR50S蛋白质语言模型进行零样本预测时,终端显示出了sequence handled的进度条,但是并不出结果就自动终止回到命令提示行了是怎么回事:
  • ¥15 前置放大电路与功率放大电路相连放大倍数出现问题
  • ¥30 关于<main>标签页面跳转的问题
  • ¥80 部署运行web自动化项目
  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测