.NET on linux, ~ / folder is wrong?

In .NET I write

Directory.CreateDirectory(textBox4.Text);

textBox4.Text ~/myfolder. What I get is a folder in the current working directory ~ with my folder. How to create CreateDirectory in my home folder?

+5
source share
3 answers

I end up using this

    string GetHome()
    {
        string homePath = (Environment.OSVersion.Platform == PlatformID.Unix ||
               Environment.OSVersion.Platform == PlatformID.MacOSX)
? Environment.GetEnvironmentVariable("HOME")
: Environment.ExpandEnvironmentVariables("%HOMEDRIVE%%HOMEPATH%");
        return homePath;
    }

        var saveDirectory = textBox4.Text;
        if (saveDirectory.StartsWith("~/"))
            saveDirectory = GetHome() + saveDirectory.Substring(1);
+1
source

Perhaps this link will help you. He discusses special folders in mono.

+3
source

(http://www.opengroup.org/onlinepubs/009695399/utilities/xcu_chap02.html#tag_02_06_01).

- bash -c "echo ~/folder" . .NET API ( C API), , , - .

- glob() C ( Linux) GLOB_TILDE, .

+2
source

All Articles