import os,re,shutil
def get_filelist(dir):
t1='{"computerPlayId":'
t2=' ,"computerPlayListArray": '
t3=', "propertyPlayId":"", "propertyPlayListArray": []}'
listid=[]
listtext=[]
for root, dirs, files in os.walk(dir):
for d in dirs:
path1=os.path.join(root,d)
print(path1)
for root1,dir1,files1 in os.walk(path1):
for f in files1:
path2=os.path.join(root1,f)
print(path2)
if f=="playList.txt":
with open(path2,'r',encoding='utf8')as file1:
t=file1.read()
matchobj=re.match('{"play_list_id":(d+?),',t)
id=matchobj.group(1)
listid.append(id)
listtext.append(t)
elif f!="pubKeyMsgPwd.txt":
path3="D:\离线节目单合成\material\"+f
shutil.copy(path2,path3)
idString=""
textString=""
for i in listid:
idString=idString+i+','
idString=idString.rstrip(',')
print(idString)
t1=t1+'"'+idString+'"'
for j in listtext:
textString=textString+','+j
textString=textString.strip(',')
print(textString)
t2=t2+'['+textString+']'
t=t1+t2+t3
with open("D:\离线节目单合成\material\playList.txt",'w')as f:
f.write(t)
if __name__ == "__main__":
get_filelist('D:\离线节目单合成\节目单')