Python 遍历文件
1 import os 2 import re 3 4 zifu = ['<audio id="','" url="','"></audio>'] 5 count = 0 6 rootdir = 'D:\\LittleWorld\\src\\audio\\common' 7 list = os.listdir(rootdir) #列出文件夹下所有的目录与文件 8 for i in range(0,len(list)): 9 path = os.path.join(rootdir,list[i]) 10 if os.path.isfile(path): 11 12 if path.find('mp3') != -1: 13 count = count + 1 14 xiabiao = path.find("audio") 15 newstr = path[xiabiao:len(path)] 16 path = zifu[0] + str(count) + zifu[1] + newstr + zifu[2] 17 print(path) 18 else: 19 # print("该文件不是MP3格式:%s"%path) 20 pass