Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- import glob
- import os
- import sys
- strPattern="[#Z Karaoke]"
- def rename(path,txt):
- txtSource=path+"/"+txt+' [Z# Karaoke].cdg'
- txtTarget=path+"/"+txt+' [Z Karaoke].cdg'
- if os.path.exists(txtSource):
- os.rename(txtSource,txtTarget)
- else:
- print("ERROR: Unable to rename",txtSource,"to",txtTarget)
- # print("RENAME",txtSource,"TO",txtTarget)
- txtSource=path+"/"+txt+' [Z# Karaoke].mp3'
- txtTarget=path+"/"+txt+' [Z Karaoke].mp3'
- if os.path.exists(txtSource):
- os.rename(txtSource,txtTarget)
- else:
- print("ERROR: Unable to rename",txtSource,"to",txtTarget)
- # print("RENAME",txtSource,"TO",txtTarget)
- def delete(path,txt):
- txtSource=txt+' [Z# Karaoke].cdg'
- # print("RENAME",path+"/"+txtSource,"TO "+path+"/"+"DELETE_"+txtSource)
- if os.path.exists(txtSource):
- os.remove(txtSource)
- else:
- print("ERROR: Unable to rename",txtSource,"for deletion")
- txtSource=txt+' [Z# Karaoke].mp3'
- # print("RENAME",path+"/"+txtSource,"TO "+path+"/"+"DELETE_"+txtSource)
- if os.path.exists(txtSource):
- os.remove(txtSource)
- else:
- print("ERROR: Unable to rename",txtSource,"for deletion")
- #print("Arguments:",len(sys.argv))
- #print(str(sys.argv))
- strPath=sys.argv[1]
- if os.path.exists(strPath):
- lstFiles=glob.glob(strPath+"/*.cdg")
- lstFiles.sort()
- if len(lstFiles)>0:
- print("Processing",len(lstFiles)*2,"files...")
- # print(lstFiles)
- for i in lstFiles:
- intRenCount=0
- intDelCount=0
- tmp=i.removeprefix(sys.argv[1]+"/")
- if "[#z karaoke]" in tmp.lower():
- lst=tmp.split(" [",2)
- lst[1]="["+lst[1]
- # print()
- found=False
- for t in lstFiles:
- # print("LOOKING FOR",lst[0].lower(),"-->",t.lower(),"***AND*** [z karaoke] --> ",t.lower())
- if lst[0].lower() in t.lower() and "[z karaoke]" in t.lower():
- found=True
- if found:
- delete(strPath,lst[0])
- intDelCount+=1
- else:
- rename(strPath,lst[0])
- intRenCount+=1
- else:
- print("ERROR: Unable to find any crg files")
- else:
- print("ERROR: Directory doesn't exist")
- if os.path.exists("D/Test.txt"):
- os.rename("D/Test.txt","D/test.txt")
- else:
- print("Failed")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement