def main():
with open('d:/test_trim.txt', 'w', encoding='UTF-8') as fout:
can_write = False
with open('d:/test.txt', '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.readline()
print('Done.')
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.')