2

I am working on a Windows C++ App, where I get a URI similar to file:///C:/test 1/file.foo. Now I want to e.g. open that URI with ifstream.

Is there any C/C++ API available on Windows to convert such a path?

My Google Foo seems to be weak today.

abergmeier
  • 13,224
  • 13
  • 64
  • 120
  • 3
    Just remove the `"file:///"` part? Or get a substring of the rest? And if the URI doesn't start with `"file:///"` then it's not something that should be opened as a file anyway. – Some programmer dude Mar 17 '17 at 12:54
  • And then there is `%` escaping and perhaps existence check. It is not as easy as you think it is. – abergmeier Mar 17 '17 at 12:59
  • 1
    There are lots of libraries and functions around that will decode URIs. I cannot believe that you can't find one. Question must have been asked here loads of times. Search harder. – David Heffernan Mar 17 '17 at 13:03
  • 1
    one possibility: https://msdn.microsoft.com/en-us/library/bb773581(v=vs.85).aspx – NathanOliver Mar 17 '17 at 13:08
  • Possibly relevant: http://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform – SergeyA Mar 17 '17 at 13:27
  • This link [http://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform](http://stackoverflow.com/questions/2616011/easy-way-to-parse-a-url-in-c-cross-platform) was in a comment, and I found it helpful. – codeDr Oct 04 '22 at 16:40
  • adding helpful comment as an answer seems difficult. – codeDr Oct 04 '22 at 16:41

2 Answers2

2

There is PathCreateFromUrl() :

https://msdn.microsoft.com/en-us/library/bb773581(v=vs.85).aspx

lowarago
  • 88
  • 8
2

There are multiple file URI "versions" so you should not parse it yourself, some of the APIs are broken as well.

If you just want a Windows style path, call PathCreateFromUrl.

If you don't want to convert the path then you must use CreateURLMonikerEx or SHParseDisplayName (with a bind context) but then you end up with a Windows IStream instead.

Anders
  • 97,548
  • 12
  • 110
  • 164