完整代码如下


#!/usr/bin/env python
# -*- coding:utf-8 -*-
# python3

import os
import re

path = "D:\\data\\filename\\"   #文件夹所在位置
filenames = os.listdir(path)
n=0
for i in filenames:
    n = n + 1
    #清除文件命中的数字
    temp = re.sub('[0-9A-Z、]', '', i)
    newname = str(n)+ '、' + i
    # data = re.compile('[0-9A-Z、a-z]+').findall(i)
    data=re.compile('[0-9]').findall(i)
    if data:
        print("Numbers already exist in the file!!!")
        # 清除文件夹名中所有数字、字母、特殊符号
        os.rename(path + i, path + temp)
        # print(temp)
    else:
        print("Add serial number")
        # 文件夹自动排序(递增)
        os.rename(path + i, path + newname)

相关文章:

  • 2021-06-01
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2023-02-10
  • 2021-04-29
  • 2022-01-15
猜你喜欢
  • 2022-01-21
  • 2022-12-23
  • 2021-08-30
  • 2022-01-04
  • 2022-01-11
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案