Thread overview
Convert path to file system path on windows
Jun 21, 2018
Dr.No
Jun 21, 2018
Timoses
Jun 21, 2018
FreeSlave
Jun 30, 2018
Dr.No
June 21, 2018
How can I do that with D?

In C# you can do that:

var filename = @"C:\path\to\my\file.txt";
var file = new Uri(filename).AbsoluteUri;
// file is "file:///C:/path/to/my/file.txt"

How can I do that in D?

June 21, 2018
On Thursday, 21 June 2018 at 18:46:05 UTC, Dr.No wrote:
> How can I do that with D?
>
> In C# you can do that:
>
> var filename = @"C:\path\to\my\file.txt";
> var file = new Uri(filename).AbsoluteUri;
> // file is "file:///C:/path/to/my/file.txt"
>
> How can I do that in D?

I don't know of a specific implementation that does the same, but I can point you to some spots you might look into:

std.path: https://dlang.org/phobos/std_path.html
std.uri: https://dlang.org/phobos/std_uri.html

vibe.inet.url: http://vibed.org/api/vibe.inet.url/URL
vibe.core.path: http://vibed.org/api/vibe.core.path/


I really feel like vibed's documentation api site is missing some nice examples of usage to get a quick feel of the provided api.
June 21, 2018
On Thursday, 21 June 2018 at 18:46:05 UTC, Dr.No wrote:
> How can I do that with D?
>
> In C# you can do that:
>
> var filename = @"C:\path\to\my\file.txt";
> var file = new Uri(filename).AbsoluteUri;
> // file is "file:///C:/path/to/my/file.txt"
>
> How can I do that in D?

import std.stdio;
import std.exception;
import core.sys.windows.windows;
import std.windows.syserror;

@safe void henforce(HRESULT hres, lazy string msg = null, string file = __FILE__, size_t line = __LINE__)
{
    if (hres != S_OK)
        throw new WindowsException(hres, msg, file, line);
}

@trusted wstring absoluteUri(string path)
{
    import std.path : absolutePath;
    import std.utf : toUTF16z;
    import core.sys.windows.shlwapi;
    import core.sys.windows.wininet;

    auto shlwapi = wenforce(LoadLibraryA("Shlwapi"), "Failed to load shlwapi");
    enforce(shlwapi !is null);
    auto urlCreateFromPath = cast(typeof(&UrlCreateFromPathW))wenforce(shlwapi.GetProcAddress("UrlCreateFromPathW"), "Failed to find UrlCreateFromPathW");
    scope(exit) FreeLibrary(shlwapi);
    wchar[INTERNET_MAX_URL_LENGTH] buf;
    auto size = cast(DWORD)buf.length;
    henforce(urlCreateFromPath(path.absolutePath.toUTF16z, buf.ptr, &size, 0));
    return buf[0..size].idup;
}

int main(string[] args)
{
    foreach(path; args)
    {
        writeln(absoluteUri(path));
    }
	return 0;
}

June 30, 2018
Thank you very much u all guys.