简体   繁体   English

如何通过在 c# 中使用 AppDomain.CurrentDomain.BaseDirectory 在文件夹路径中上一步

[英]How to go one step above in a folder path by using AppDomain.CurrentDomain.BaseDirectory in c#

I am using AppDomain.CurrentDomain.BaseDirectory and I want to go one step backwards but couldn't figure out how?我正在使用AppDomain.CurrentDomain.BaseDirectory ,我想倒退一步,但不知道怎么做? Below is the example,下面是例子,

CODE :代码 :

string path = AppDomain.CurrentDomain.BaseDirectory;

RESULT :结果 :

"C:\\\\Mainline Code\\\\IxExpress\\\\.NET Applications\\\\IXTextIndexBuilder\\\\IXTextIndexBuilder\\\\bin\\\\Debug\\\\"

EXPECTED RESULT:预期结果:

"C:\\\\Mainline Code\\\\IxExpress\\\\.NET Applications\\\\IXTextIndexBuilder\\\\IXTextIndexBuilder\\\\bin"

You can use something like the following to get the parent of a given directory:您可以使用类似以下内容来获取给定目录的父目录:

        string dirName = AppDomain.CurrentDomain.BaseDirectory; // Starting Dir
        FileInfo fileInfo = new FileInfo(dirName);
        DirectoryInfo parentDir = fileInfo.Directory.Parent;
        string parentDirName = parentDir.FullName; // Parent of Starting Dir

使用以下代码段:

string path = (new FileInfo(AppDomain.CurrentDomain.BaseDirectory)).Directory.Parent.FullName;

Directory.GetParent(AppDomain.CurrentDomain.BaseDirectory).Parent.FullName

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C#Uri AppDomain.CurrentDomain.BaseDirectory相对路径 - C# Uri AppDomain.CurrentDomain.BaseDirectory relative path 如何模拟AppDomain.CurrentDomain.BaseDirectory - How to mock AppDomain.CurrentDomain.BaseDirectory 运行MVC项目时AppDomain.CurrentDomain.BaseDirectory路径问题 - AppDomain.CurrentDomain.BaseDirectory path issue when running MVC project AppDomain.CurrentDomain.BaseDirectory 更改为错误的目录 - AppDomain.CurrentDomain.BaseDirectory changes to wrong directory 在本地调试Azure函数为AppDomain.CurrentDomain.BaseDirectory提供了一条有趣的路径 - Debugging Azure function locally gives a funny path to AppDomain.CurrentDomain.BaseDirectory AppDomain.CurrentDomain.BaseDirectory会根据应用程序的目标平台进行更改 - AppDomain.CurrentDomain.BaseDirectory changes according to the app's target platform AppDomain.CurrentDomain.BaseDirectory运行测试后会发生变化吗? - AppDomain.CurrentDomain.BaseDirectory changes after running test? 为什么 AppDomain.CurrentDomain.BaseDirectory 在控制台应用程序中定位 bin catelog? - Why is AppDomain.CurrentDomain.BaseDirectory targeting bin catelog in console application? 我应该使用 AppDomain.CurrentDomain.BaseDirectory 还是 System.Environment.CurrentDirectory? - Should I use AppDomain.CurrentDomain.BaseDirectory or System.Environment.CurrentDirectory? 为什么 AppDomain.CurrentDomain.BaseDirectory 在 asp.net 应用程序中不包含“bin”? - Why AppDomain.CurrentDomain.BaseDirectory not contains "bin" in asp.net app?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM