How do I find the parent directory in C#?

后端 未结 15 695
旧时难觅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:23

    This is the most common way -- it really depends on what you are doing exactly: (To explain, the example below will remove the last 10 characters which is what you asked for, however if there are some business rules that are driving your need to find a specific location you should use those to retrieve the directory location, not find the location of something else and modify it.)

    // remove last 10 characters from a string
    str_directory = str_directory.Substring(0,str_directory.Length-10);
    

提交回复
热议问题