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 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵