文件遍历升级版
1 import os 2 import re 3 4 zifu = ['<audio id="','" url="','"></audio>'] 5 count = 0 6 7 def traverse(f): 8 global count 9 fs = os.listdir(f) 10 for f1 in fs: 11 tmp_path = os.path.join(f,f1) 12 if not os.path.isdir(tmp_path): 13 # print("文件:%s"%tmp_path) 14 15 if tmp_path.find('mp3') != -1: 16 if tmp_path.find('meta') != -1: 17 pass 18 else: 19 count = count + 1 20 xiabiao = tmp_path.find("audio") 21 newstr = tmp_path[xiabiao:len(tmp_path)] 22 tmp_path = zifu[0] + str(count) + zifu[1] + newstr + zifu[2] 23 print(tmp_path) 24 else: 25 pass 26 27 else: 28 # print("文件夹:%s"%tmp_path) 29 traverse(tmp_path) 30 31 path = "C:\\Users\\13917630495\\Desktop\\audio" 32 traverse(path)