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 should look at the python string method translate()
http://docs.python.org/library/string.html#string.translate
with
http://docs.python.org/library/string.html#string.maketrans
import string
toreplace=''.join(["/", "\\", ":", "(", ")", "<", ">", "|", "?", "*"])
underscore=''.join( ['_'] * len(toreplace))
transtable = string.maketrans(toreplace,underscore)
filename = filename.translate(transtable)
foldername = foldername.translate(transtable)
Can simplify by making the toreplace something like '/\:,' etc, i just used what was given above