如何在C#中找到父目录? [英] How do I find the parent directory in C#?

查看:103
本文介绍了如何在C#中找到父目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用这个代码找到调试目录

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\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\

"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

推荐答案

您可以使用 System.IO.Directory.GetParent()来检索给定目录的父目录。

You can use System.IO.Directory.GetParent() to retrieve the parent directory of a given directory.

这篇关于如何在C#中找到父目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆