对下面的有序文件夹中的文件重命名,使文件名为文件夹名+1,2……等命名方式

python批量处理有序文件夹中的文件重命名

 

import os;

def rename(str1):
        i=0
        path="F:\\test\\"+str1;
        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, str1+'-'+str(i)+filetype);#新的文件路径
            os.rename(Olddir,Newdir)#重命名

for i in range(1, 6):
    rename('模拟'+str(i))
    rename('模拟'+str(i)+' 答案')

相关文章:

  • 2022-12-23
  • 2021-06-19
  • 2022-12-23
  • 2021-12-15
  • 2021-12-27
  • 2022-01-01
  • 2021-09-13
  • 2022-01-15
猜你喜欢
  • 2021-06-18
  • 2021-10-16
  • 2022-12-23
  • 2021-05-29
  • 2021-09-28
  • 2021-11-27
相关资源
相似解决方案