Some background information: We have an ancient web-based document database system where I work, almost entirely consisting of MS Office documents with the \"normal\" extens
You are starting over with the base line instead of saving the replaced result, thus you are getting the equivalent to
filename = line[2].replace('*', '_')
foldername = line[5].replace('*', '_')
Try the following
bad_characters = ["/", "\\", ":", "(", ")", "<", ">", "|", "?", "*"]
filename = line[2]
foldername = line[5]
for letter in bad_characters:
filename = filename.replace(letter, "_")
foldername = foldername.replace(letter, "_")