I would like to use Python to rename the files in a directory called myShow
from a .txt file that contains the "target" names:
realNameForEpisode1
realNameForEpisode2
realNameForEpisode3
The hierarchy looks like:
episodetitles.txt
myShow
├── ep1.m4v
├── ep2.m4v
└── ep3.m4v
I tried the following:
import os
with open('episodetitles.txt', 'r') as txt:
for dir, subdirs, files in os.walk('myShow'):
for f, line in zip(sorted(files), txt):
originalName = os.path.abspath(os.path.join(dir, f))
newName = os.path.abspath(os.path.join(dir, line + '.m4v'))
os.rename(originalName, newName)
but I don't know why I get a ?
at the end of the filename before the extension:
realNameForEpisode1?.m4v
realNameForEpisode2?.m4v
realNameForEpisode3?.m4v