Python批量重命名指定文件夹下文件的两种方法

#法一import ospath = "C://Python34//"for file in os.listdir(path):if os.path.isfile(os.path.join(path,file))==True:if file.find('.')<0:newname=file+'.jpg'os.rename(os.path.join(path,file),os.path.join(path,newname))#法二import osimport globpath = "C://Python34//"for infile in glob.glob( os.path.join(path, '*.gif') ):for i in range (1,21):index_symbol = "_" + str(i) + "_"if index_symbol in infile:newfile = infilenewfile = newfile.replace(index_symbol, str(i));os.rename(infile, newfile)print (infile)

,明天是世上增值最快的一块土地,因它充满了希望

Python批量重命名指定文件夹下文件的两种方法

相关文章:

你感兴趣的文章:

标签云: