Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python3
- #PURPOSE: Find double spaces anywhere within a filename and replace with just one
- import glob
- import os
- import sys
- intCount=0
- strPath=sys.argv[1]
- if os.path.exists(strPath):
- lstFiles=glob.glob(strPath+"/*.cdg") #get the contents of the directory
- lstFiles.sort()
- if len(lstFiles)>0:
- print("Processing",len(lstFiles)*2,"files...")
- # print(lstFiles)
- for i in lstFiles:
- tmp=i.removeprefix(sys.argv[1]+"/") #remove the path
- tmp=tmp.removesuffix(".cdg") #remove the file extension
- pos=tmp.find(" ") #See if there's double spaces within the filename
- # print(f"File: {tmp} ({pos})")
- if pos>=0:
- tmpAR=tmp.split(" ") #split the filename on the two spaces
- os.rename(sys.argv[1]+"/"+tmp+".cdg",sys.argv[1]+"/"+tmpAR[0]+" "+tmpAR[1]+".cdg")
- os.rename(sys.argv[1]+"/"+tmp+".mp3",sys.argv[1]+"/"+tmpAR[0]+" "+tmpAR[1]+".mp3")
- intCount+=1
- if intCount>0:
- print(f"Stripped double spaces from {intCount*2} files.")
- else:
- print("ERROR: Unable to find any cdg files")
- else:
- print("ERROR: Directory doesn't exist")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement