0

Could I use std::filesystem::path::extension to extract the extension of a file for which I have an http address in string format? For local path the discussion can be found here

More in general could I use also its siblings methods stem and filename?

If not, is there any reliable alternative than doing it manually as spelled out in the other pre-C++17 answer?

Antonio
  • 19,451
  • 13
  • 99
  • 197
  • 1
    In general case I do not think so. Note that url has query and fragment which are placed after stem – Marek R Apr 21 '23 at 16:06

1 Answers1

4

The URL specification does not fit with the filesystem::path generic path specification. URLs can do things that don't work as intended with filesystem::paths. So while it might be able to work in some cases, there is no guarantee that it will work in all of them.

Nicol Bolas
  • 449,505
  • 63
  • 781
  • 982
  • And there is no alternative to perform this task explicitly, correct? – Antonio Apr 22 '23 at 04:53
  • @Antonio: The C++ standard library doesn't have a tool for interacting with a URL, no. I'm sure there are libraries out there that can do that. – Nicol Bolas Apr 22 '23 at 13:37
  • Okay, for curl (which is the library I am using) getting the filename might be pretty complicated, the subject is treated [here](https://stackoverflow.com/questions/25576697/libcurl-how-to-download-url-with-original-filename-equivalent-for-o-remot) – Antonio Apr 24 '23 at 09:57