[英]Python: Rename multiple files in folder with name that come from a list
我想構建一個小應用程序,重命名文件夾中的文件,其中一些名稱位於 txt 文件中,如下所示:
在C:\python\Folder我有文件: 1436790.pdf 1436791.pdf 1436792.pdf
在file.txt我有 3 行:
重命名應該是:
我不知道os.rename()
是如何工作的。 我收到這個錯誤
**"OSError: [WinError 87] The parameter is incorrect:"**
我嘗試使用 Total Commander 多重重命名工具(從文件加載名稱)以類似的方式制作此應用程序。
basefolder=r'C:\python\Folder'
with open('file.txt', 'r') as fh:
read_lines = fh.readlines()
files=os.listdir(basefolder)
for file in r(files):
fn,fext=os.path.splitext(files[file])
os.rename(files[file], read_lines[file]+fext )
看起來這是由於 pytest/Python 錯誤問題。 參考https://github.com/pytest-dev/pytest/issues/5724
現在嘗試降級到 Python 3.7.3,直到有人找到修復程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.