参考文章:http://www.cnblogs.com/ma6174/archive/2012/05/04/2482378.html

最近遇到一个问题,在网上下载了一批视频课程,需要将每节课的名称标号,方便排序观看,正好看了两天python语法,就想着用python实现一个简单的改名字的程序,果然有人已经做了,参考一下前辈的文章代码,差了点资料,就实现了一个简单的改名字的程序。

代码是参考前辈的,如有侵权请联系。

# -*- coding: utf-8 -*-
'change file names automaticlly'
import os
filepath = 'D://视频/法语/31~60'
#filepath = 'D://视频/法语/11~30'
#给每个文件名称开头添加数字序号
for filename in os.listdir(filepath):
    list = filename.split(' ')
    temp = filename
    head = ''
    for word in list:
        if word.isdigit() == True:
            if int(word) > 10:
                head = word + ' '
    
    newname = head + filename
    os.rename(os.path.join(filepath, filename), os.path.join(filepath, newname))
    print(newname)

最后的效果:

python批量修改文件名称

 

 

相关文章:

  • 2021-11-23
  • 2021-12-13
  • 2021-10-16
  • 2022-12-23
  • 2021-10-05
  • 2021-10-26
  • 2021-11-29
猜你喜欢
  • 2021-12-23
  • 2021-12-13
  • 2021-12-13
  • 2021-05-31
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案