How do I find the parent directory in C#?

后端 未结 15 706
旧时难觅i
旧时难觅i 2020-11-29 05:04

I use this code for finding the debug directory

public string str_directory = Environment.CurrentDirectory.ToString();

\"C:\\\\Us

15条回答
  •  生来不讨喜
    2020-11-29 05:30

    If you append ..\.. to your existing path, the operating system will correctly browse the grand-parent folder.

    That should do the job:

    System.IO.Path.Combine("C:\\Users\\Masoud\\Documents\\Visual Studio 2008\\Projects\\MyProj\\MyProj\\bin\\Debug", @"..\..");
    

    If you browse that path, you will browse the grand-parent directory.

提交回复
热议问题