我有这个代码的问题。我正在尝试重命名文件夹中的所有文件名,以便它们不再包含+'s
在其中!这已经工作了很多次,但突然我得到了错误:
WindowsError: [Error 2] The system cannot find the file specified at line 26
第 26 行是代码的最后一行。
有谁知道为什么会这样?我只是向某人保证我可以在 5 分钟内完成这项工作,因为我有一个代码!可惜没用!!
import os, glob, sys
folder = "C:\\Documents and Settings\\DuffA\\Bureaublad\\Johan\\10G304655_1"
for root, dirs, filenames in os.walk(folder):
for filename in filenames:
filename = os.path.join(root, filename)
old = "+"
new = "_"
for root, dirs, filenames in os.walk(folder):
for filename in filenames:
if old in filename:
print (filename)
os.rename(filename, filename.replace(old,new))