记录且分享平时学习所得
过程或许有些冗杂
#!python3
#creating a new dir,which exits lacing number
#adding these number
#1.cerating regex to mach the name, using '()'to ensure the lacking number
import re,os,shutil
def complenum(folder):
format=re.compile(r"""^(.*)_ #words of begining
(\d\d\d) #the middle number
(.*?)$ # postfix
""",re.VERBOSE)
count=0
#2..loop file、finding filesname
for foldername,subfolders,filenames in os.walk(folder):
for filename in filenames:
#print('filename:"%s"',filenames)
# print(type(filename))
mo=format.search(filename)
if mo!=None:
count+=1
#3.judging if number lacking and replace them
if count!=format.search(filename).group(2):
newfilename=format.sear