[英]Python: Rename multiple files in folder with name that come from a list
I want to build a small app that renameS files that are in a folder with some names that are in a txt file like so:我想构建一个小应用程序,重命名文件夹中的文件,其中一些名称位于 txt 文件中,如下所示:
in C:\python\Folder i have files: 1436790.pdf 1436791.pdf 1436792.pdf在C:\python\Folder我有文件: 1436790.pdf 1436791.pdf 1436792.pdf
in file.txt I have 3 lines:在file.txt我有 3 行:
Renaming should be:重命名应该是:
I can't figure out how os.rename()
is working.我不知道os.rename()
是如何工作的。 I'm getting this error我收到这个错误
**"OSError: [WinError 87] The parameter is incorrect:"**
I tried to make this app in a similar way with Total Commander multi rename tool (load names from file).我尝试使用 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 )
Looks like this is due to the pytest/Python bug issue.看起来这是由于 pytest/Python 错误问题。 Refer https://github.com/pytest-dev/pytest/issues/5724参考https://github.com/pytest-dev/pytest/issues/5724
For now try downgrading to Python 3.7.3 until someone finds a fix.现在尝试降级到 Python 3.7.3,直到有人找到修复程序。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.