我正在尝试摆脱源文件夹中的非字母数字字符,并将任何具有非字母数字字符的文件重命名为版本,而不使用此代码。但是,每次我运行该模块时,我都会收到此错误,
Traceback (most recent call last):
File "C:\tempstore\Filescan1", line 18, in <module>
os.rename(filename,newfilename)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process
请帮忙?
os.chdir("C:\\tempstore\\source")
file_list = glob.glob("*.mpg*")
for filename in file_list:
if re.search('[^A-Za-z0-9._ ]+',filename,re.U) is not None:
print filename + " <--Dodgy File"
print re.sub('[^0-9a-zA-Z+_. ]+','-',filename)+ " <--Fixed File"
newfilename = re.sub('[^0-9a-zA-Z+_. ]+','-',filename)
os.rename(filename,newfilename)
elif re.search('[^A-Za-z0-9._ ]+',filename,re.U) is None:
print filename +" <-- Normal File"
unchanged_list = re.sub('[^A-Za-z0-9._ ]+','_',filename)
print unchanged_list