gpt4 book ai didi

c# - System.IO.Path.GetDirectoryName 使路径无效

转载 作者:行者123 更新时间:2023-12-02 21:44:33 25 4
gpt4 key购买 nike

我正在尝试执行一个工具exe,它与主exe位于同一目录中。为此,我尝试首先使用 Assembly.GetExecutingAssembly 获取进程的 exe 名称,然后使用 IO.Path.GetDirectoryName 获取目录

//1
String exePath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase;
//2
String ncpath = System.IO.Path.GetDirectoryName(exePath);

1 返回“file:///C:/Development/RC_trunk/bin/Release/ResultConfirmation.EXE”它是一个 URI。不完全是我需要的,但还可以。

2 返回“file:\C:\Development\RC_trunk\bin\Release” 这似乎是一个简单的 [/]+ 到\替换。

我是否使用了错误的 API 来解决我的问题?

附注IDE是VS2008

最佳答案

要获取应用程序目录,请尝试AppDomain.CurrentDomain.BaseDirectory

看看Best way to get application folder path了解访问目录的其他方式。

关于c# - System.IO.Path.GetDirectoryName 使路径无效,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19757904/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com