文件遍历升级版

 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)

 

转载于:https://www.cnblogs.com/Hunter-541695/p/9573357.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值