python批量重命名

版权声明:添加我的微信wlagooble,开启一段不一样的旅程 https://blog.csdn.net/nineship/article/details/82914116
#coding:utf8
import os;

def rename():
        i=0
        path="F:\test";
        filelist=os.listdir(path)#该文件夹下所有的文件(包括文件夹)
        for files in filelist:#遍历所有文件
            i=i+1
            Olddir=os.path.join(path,files);#原来的文件路径                
            if os.path.isdir(Olddir):#如果是文件夹则跳过
                    continue;
            filename=os.path.splitext(files)[0];#文件名
            filetype=os.path.splitext(files)[1];#文件扩展名
            Newdir=os.path.join(path,str(i)+filetype);#新的文件路径
            os.rename(Olddir,Newdir)#重命名
rename()

https://www.cnblogs.com/jachin01/p/7213903.html?utm_source=itdadao&utm_medium=referral

猜你喜欢

转载自blog.csdn.net/nineship/article/details/82914116