import os
s = os.sep
#全局变量
List_Err = []
#dirroot = "D:" + s + "实验报告" + s #要遍历的目录
currentdir = os.path.abspath('.') #遍历当前目录
#print(currentdir)
#文件名有空格,则重新命名
for rt, dirs, files in os.walk(currentdir):
for f in files:
fname = os.path.splitext(f)
if fname[1] == ".rar" or fname[1] == ".zip" or fname[1] == ".7z":
if ' ' in fname[0]:
try:
os.rename(currentdir + s + f, currentdir + s +
fname[0].replace(" ","") + fname[1])
except Exception as e:
print('重命名失败:'+e)
for rt, dirs, files in os.walk(currentdir):
for f in files:
fname = os.path.splitext(f)
if fname[1] == ".rar" or fname[1] =&