DNS
DNS

Reputation: 38199

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

Upvotes: 4

Views: 3752

Answers (3)

Assaf Lavie
Assaf Lavie

Reputation: 76063

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

Upvotes: 3

Tim Sylvester
Tim Sylvester

Reputation: 23148

There's the UrlCreateFromPath API:

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

Upvotes: 8

Goz
Goz

Reputation: 62333

Surely it just comes down to replacing the "\" with "/" and adding file:// on the front??

Upvotes: 0

Related Questions