导航

C# 获取目录路径

Posted on 2019-09-15 14:57  ZeroSymbol  阅读(1773)  评论(0编辑  收藏  举报
Console.WriteLine(System.Windows.Forms.Application.StartupPath);//获取启动了应用程序的可执行文件的路径,不包括可执行文件的名称。(Windows From应用程序才有效)
//输出结果:C:\GetPathInfo\GetPath\bin\Debug

Console.WriteLine(System.Environment.CurrentDirectory);//获取或设置当前工作目录的完全限定路径。
//输出结果:C:\GetPathInfo\GetPath\bin\Debug

Console.WriteLine(System.IO.Directory.GetCurrentDirectory());//获取应用程序的当前工作目录。
//输出结果:C:\GetPathInfo\GetPath\bin\Debug

Console.WriteLine(System.AppDomain.CurrentDomain.BaseDirectory);//获取基目录,它由程序集冲突解决程序用来探测程序集。
//输出结果:C:\GetPathInfo\GetPath\bin\Debug\

Console.WriteLine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase);//获取或设置包含该应用程序的目录的名称。
//输出结果:C:\GetPathInfo\GetPath\bin\Debug\

Console.WriteLine(System.Windows.Forms.Application.ExecutablePath);//获取启动了应用程序的可执行文件的路径,包括可执行文件的名称。(Windows From应用程序才有效)
//输出结果:C:\GetPathInfo\GetPath\bin\Debug\GetPath.EXE

Console.WriteLine(System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);//获取模块的完整路径。
//输出结果:C:\GetPathInfo\GetPath\bin\Debug\GetPath.vshost.exe

此处项目路径是:C:\GetPathInfo\