码迷,mamicode.com
首页 > 编程语言 > 详细

Python 遍历文件

时间:2018-07-28 15:26:17      阅读:165      评论:0      收藏:0      [点我收藏+]

标签:list   pass   mp3   world   listdir   join   port   little   str   

 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 遍历文件

标签:list   pass   mp3   world   listdir   join   port   little   str   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!