Is there a C++/win32 library function to convert a file path to a file:// URL?
I have an LPTSTR
for a file path, i.e. C:\Program Files\Ahoy
. I would like to convert it to a file://
URL that I can pass to ShellExecute in order to start the system's default browser pointing at the file. I don't want to give the path to ShellExecute directly since file associations may result in it being opened by something other than a web browser. The path is arbitrary, and may contain characters that need to be开发者_JS百科 escaped.
Is there an existing library function, along the lines of Python's urllib.pathname2url, that does this translation? This can be done via the Uri class in .NET, but I haven't found anything for plain win32.
There's the UrlCreateFromPath
API:
http://msdn.microsoft.com/en-us/library/bb773773%28VS.85%29.aspx
There's an entire path handling library within Win32. It's called Shell Path Handling Functions.
Surely it just comes down to replacing the "\" with "/" and adding file:// on the front??
精彩评论