Mar-21-2018, 04:58 AM
I need to write a small script that creates 'ffmpeg' code and therefore need to escape whitespaces and parenthesis in the filenames.
Have looked at a few ways to do this and keep getting errors. Here is what I have tried
https://docs.python.org/3/library/shlex....hlex.quote
https://pypi.python.org/pypi/shellescape
This doesn't quite do what I wanted:
Have looked at a few ways to do this and keep getting errors. Here is what I have tried
https://docs.python.org/3/library/shlex....hlex.quote
https://pypi.python.org/pypi/shellescape
This doesn't quite do what I wanted:
#!/usr/bin/python3
import re
import glob, os
for file in glob.glob("chunk*.txt"):
print(re.escape(file))Where the filename is chunk-the quick brown (fox) jumped.txt the output is Output:chunk\-the\ quick\ brown\ \(fox\)\ jumped\.txtWhere the filename is chunk-182.txt the output is Output:chunk\-182\.txtI don't need the dashes or periods escaped, only whitespace, parenthesis and square brackets.
