I use this code for finding the debug directory
public string str_directory = Environment.CurrentDirectory.ToString();
"C:\\Users\\Masoud\\Documents\\Visual Studio 2008\\Projects\\MyProj\\MyProj\\bin\\Debug"
How can I find the parent folder as shown below?
"C:\\Users\\Masoud\\Documents\\Visual Studio 2008\\Projects\\MyProj\\MyProj"
With a directory, a parent directory is a directory containing the current directory. For example, in the MS-DOS path below, the "Windows" directory is the parent directory of the "System32" directory, and C:\ is the root directory.
The .. means “the parent directory” of your current directory, so you can use cd .. to go back (or up) one directory. cd ~ (the tilde). The ~ means the home directory, so this command will always change back to your home directory (the default directory in which the Terminal opens).
.. (double-dot) is the parent of your current directory. ~ (tilde) is your home directory. / (slash) if it present at first character, it usually is called root directory.
You can use System.IO.Directory.GetParent()
to retrieve the parent directory of a given directory.
string parent = System.IO.Directory.GetParent(str_directory).FullName;
See BOL
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With