Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to quote paths on windows? (similar to shlex.quote)

I need to quote a path in a portable way, shlex.quote is converting slashes to / on windows, which causes the command to fail (using the default windows command prompt).


Returning C:/Users/Me/Documents/Projects/Test

Instead of C:\Users\Me\Documents\Projects\Test


How can I quote a path on windows, similar to shlex.quote that uses native slashes, suitable for the windows command prompt and BAT files?

like image 210
ideasman42 Avatar asked Sep 14 '25 18:09

ideasman42


1 Answers

As mentioned by some comments, your problem might not be caused by shlex.quote().

Nevertheless there is the module mslex which provides mslex.quote() and mslex.split() for the Windows shell, just like what shlex provides for the Unix shell.

like image 97
Adrian Friedli Avatar answered Sep 17 '25 08:09

Adrian Friedli