首页 > 编程语言 > 详细

Python 遍历文件

时间:2018-07-28 14:38:14      阅读:127      评论:0      收藏:0      [点我收藏+]
 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

 

Python 遍历文件

原文:https://www.cnblogs.com/Hunter-541695/p/9381739.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!