Reputation: 1949
I have a python program that receives a file path as an argument.
The problem is, that if the file path has the following chars: "%cd", then it replaces "%cd" with the current directory.
So for example:
python program.py "C:\%af%32%cd%7f.htm"
The sys.argv (in program.py) shows this:
['program.py', 'C:\\%af%32C:\\%7f.htm']
Why is that happening and how can it be solved?
Edit
The problem is that if I put "%cd" in the command line, then in python I get the command line with the current directory string instead the "%cd" chars
Upvotes: 0
Views: 264
Reputation: 96197
Escaping % with %% only works within batch files, not on the commandline. It is possible to escape % with double quote
eg:
python untitled0.py "C:\\"%"af"%"32"%"cd"%"7f.htm"
['untitled0.py', 'C:\"%af%32%cd%7f.htm']
But this is a bit tedious - and you have to be careful of \
escaping any of the "
.
Another alternative would be to replace % with some other symbol and then change it back inside the python program?
Upvotes: 2