import os
path='E:\\白嫖音樂\\' l=[] def readfiles(folderpath):
filelist=os.listdir(folderpath)
for name in filelist:
filepath=os.path.join(folderpath,name)
if os.path.isfile(filepath):
if '--' in filepath.split('\\')[-1]:
# print(filepath)
name=filepath.split('\\')[-1].split('--')[0]
if '.' in name:
if name[1]=='.' or name[2]=='.':
name=name.split('.')[-1]
l.append(name)
# if '--' not in filepath.split('\\')[-1]:
# print(filepath)
else:
readfiles(filepath)
return(l)
l1=readfiles(path) print(l1)
file='C:\\Users\\ltysd\\PycharmProjects\\pythonProject\\新建 文本文檔.txt'
f=open(file,'r',encoding='utf-8')
l=f.readlines()
for item in l:
if '' in item and '' in item: item=item.strip() song=item.split('[[')[-1].split(']]')[0] if '|' in song: song=song.split('|')[-1]
if song not in l1:
print(song)