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:
Where the filename is
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:
1 2 3 4 5 6 7 |
#!/usr/bin/python3 import re import glob, os for file in glob.glob( "chunk*.txt" ): print (re.escape( file )) |
chunk-the quick brown (fox) jumped.txt
the output is Output:chunk\-the\ quick\ brown\ \(fox\)\ jumped\.txt
Where the filename is chunk-182.txt
the output is Output:chunk\-182\.txt
I don't need the dashes or periods escaped, only whitespace, parenthesis and square brackets.