I have a problem replacing strings in python.
I have several files that contain certain string i.e. eam.
so if I have the files
scream.srt and scream eam.txt
when I run the code to replace or remove eam I end up with scrcream (Replace) or scr.srt/scr.srt
How do I target only the eam part not the "EAM" in Scream.
string_tofind
string_replacewith
for files in glob.glob("*"):
filename = os.path.splitext(files)
ext = filename[-1]
thefile = filename[0]
print(filename[0])
if string_tofind in thefile:
print("String Found")
change = thefile.replace(string_tofind , string_replacewith) + ext
print(change)
os.rename(files, change)
else:
print("String not found")