首页 > 代码库 > 重命名某一路径下文件

重命名某一路径下文件


"""
rename files


"""
# --*-- encoding:utf-8 --*--


import os


Number = 0
newnames = []


def rnfiles(path=None):
global Number

filesname = os.listdir(path)


# 图片总的组数
groups = int(len(filesname)/2)


# print(groups)

# 两张图片作为一组
for i in range(Number, groups):
for i in range(0, 1):
filename1 = "IMG_%d_xxxx_5312x3984.jpg" %(Number+1)
filename2 = "IMG_%d_yyyy_5312x3984.jpg" %(Number+1)
Number += 1
newnames.append(filename1)
newnames.append(filename2)


for i in range(0,len(filesname)):
os.walk(path)
os.rename(path+"\\"+filesname[i], path+"\\"+newnames[i])
print("完成地%d组命名" %(i+1))


 


if __name__ == ‘__main__‘:
rnfiles("C:\\Users\\xxx\\Desktop\\xxxx")

 

 

重命名某一路径下文件