Ive made this quick program to strip the "youtube - " prefix off my mp3 collection, so i started modifying a script i had made before to replace file names with a <filename><incrementing number> type name.
It has gone well so far, with the only problem being it will strip "you" as oposed to the entire thing if the song title begins with you as you will see in my output.
Can anyone help?
import os, string
from os.path import join as pjoin, isdir
while True:
targetfolder = raw_input('enter a target folder:\n').strip()
if isdir(targetfolder):
os.chdir(targetfolder)
break
else:
print("you must enter an existing folder!")
toBeStripped = "YouTube -" #raw_input('enter a string to be stripped:\n')
for fname in os.listdir(targetfolder):
print fname
c = os.path.splitext(fname) # so the file extension remains the same after edit
fname2 = c[0].strip(toBeStripped) + c[1] # tries stripping the phrase
newname = pjoin(targetfolder, fname2)
print fname2
os.rename(fname, newname)
Thank you for your time.