- 帖子
- 909
- 积分
- 1215
- 技术
- 3
- 捐助
- 0
- 注册时间
- 2018-1-17
|
3楼
发表于 2020-4-26 15:08
| 只看该作者
回复 1# netdzb
# -*- coding:utf-8 -*-
import os
def getFiles(dir, suffix): # 查找根目录,文件后缀
res = []
for root, directory, files in os.walk(dir): # =>当前根,根下目录,目录下的文件
for filename in files:
name, suf = os.path.splitext(filename)
if suf == suffix:
res.append(os.path.join(root, filename))
return res
if __name__ == '__main__':
for file in getFiles(".", '.cue'): # =>查找以.cue结尾的文件
# print(file)
with open('qumi.txt', 'w+',encoding='UTF-8') as fout:
can_write = False
with open('file', 'r',encoding='UTF-8') as fin:
line = fin.readline()
while(line != ''):
if line.find('TRACK') == -1:
line = fin.readline()
continue
if line.find('TITLE') > -1:
print line
fout.write(line)
line = fin.readlin()
print('Done.')
python 2.7貌似对中文目录支持不好,文件没有读到呢~,上面是我的代码。 |
|