[英]How can iI get the current path and not the path of exe in c#?
我在C#
中發布了一個console project
,並將其放在path environment
FE c:\some\path\project.exe
中。 可執行文件具有以下代碼。
Console.WriteLine(Environment.GetCommandLineArgs()[0]);
Console.WriteLine(System.AppContext.BaseDirectory);
Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine(Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location));
Console.WriteLine(Path.GetDirectoryName(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName));
當我執行它時。 在 cmd 我得到以下內容:
c:\here\here\here > project.exe
c:\some\path\project.dll
c:\some\path\
c:\some\path\
c:\some\path
c:\some\path
我需要獲取路徑c:\here\here\here
試試這個: Console.WriteLine(Directory.GetCurrentDirectory());
除了 Dharati 的回答中建議的內容之外,您還可以執行以下操作:
string fullPath = System.Reflection.Assembly.GetEntryAssembly().Location;
string noFileNamePath = fullPath.Substring(0, (fullPath.LastIndexOf('\\') + 1));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.