Mar-21-2018, 09:12 AM
(Mar-21-2018, 06:47 AM)Gribouillis Wrote: Use .....
Thanks, that works just fine on whitespaces, left and right parenthesis and left and right square brackets.
#!/usr/bin/python3 import re import glob, os os.chdir("/home/somepath") _to_esc = re.compile(r'\s|[]()[]') def _esc_char(match): return '\\' + match.group(0) def my_escape(name): return _to_esc.sub(_esc_char, name) for file in glob.glob("chunk*.txt"): file = my_escape(file) print(file)