C#文件目录

文件所在位置

C#文件目录_第1张图片

代码 

Console.WriteLine("获取程序的基目录" + System.AppDomain.CurrentDomain.BaseDirectory);
Console.WriteLine("获取模块的完整路径" + System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName);
Console.WriteLine("获取和设置当前目录(该进程从中启动的目录)的完全限定目录" + System.Environment.CurrentDirectory);
Console.WriteLine("获取应用程序的当前工作目录" + System.IO.Directory.GetCurrentDirectory());
Console.WriteLine("获取和设置包括应用程序的目录的名称" + System.AppDomain.CurrentDomain.SetupInformation.ApplicationName);
Console.WriteLine("获取启动应用程序的可执行文件的路径" + System.Windows.Forms.Application.StartupPath);
Console.WriteLine("获取启动应用程序的可执行文件的路径及名称" + System.Windows.Forms.Application.ExecutablePath);

结果

获取程序的基目录E:\workspace\consoleapp\WindowsFormsApp1FilePath\WindowsFormsApp1FilePath\bin\Debug\


获取模块的完整路径E:\workspace\consoleapp\WindowsFormsApp1FilePath\WindowsFormsApp1FilePath\bin\Debug\WindowsFormsApp1FilePath.exe


获取和设置当前目录(该进程从中启动的目录)的完全限定目录E:\workspace\consoleapp\WindowsFormsApp1FilePath\WindowsFormsApp1FilePath\bin\Debug


获取应用程序的当前工作目录E:\workspace\consoleapp\WindowsFormsApp1FilePath\WindowsFormsApp1FilePath\bin\Debug


获取和设置包括应用程序的目录的名称WindowsFormsApp1FilePath.exe


获取启动应用程序的可执行文件的路径E:\workspace\consoleapp\WindowsFormsApp1FilePath\WindowsFormsApp1FilePath\bin\Debug


获取启动应用程序的可执行文件的路径及名称E:\workspace\consoleapp\WindowsFormsApp1FilePath\WindowsFormsApp1FilePath\bin\Debug\WindowsFormsApp1FilePath.exe


 

归纳

目录

1.System.AppDomain.CurrentDomain.BaseDirectory比其他三个末尾多一个\

2.System.Environment.CurrentDirectory

3.System.IO.Directory.GetCurrentDirectory()

4.System.Windows.Forms.Application.StartupPath

目录及名称

1.System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName

2.System.Windows.Forms.Application.ExecutablePath

参考文献

AppDomain.CurrentDomain.BaseDirectory是什么

你可能感兴趣的:(C#,c#,目录)