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 
    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



```

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

img

你前面代码里路径是111111
后面报错信息是11111
有点诡异呀

找到原因了!!因为windows对文件路径有要求,文件路径里不能有:/?