Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a C++/win32 library function to convert a file path to a file:// URL?

Tags:

c++

winapi

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 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.

like image 265
DNS Avatar asked Dec 18 '22 04:12

DNS


2 Answers

There's the UrlCreateFromPath API:

http://msdn.microsoft.com/en-us/library/bb773773%28VS.85%29.aspx

like image 124
Tim Sylvester Avatar answered Feb 16 '23 00:02

Tim Sylvester


There's an entire path handling library within Win32. It's called Shell Path Handling Functions.

like image 41
Assaf Lavie Avatar answered Feb 15 '23 22:02

Assaf Lavie