C#文件目录

文件所在位置

代码

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是什么

相关推荐
__water4 小时前
『功能项目』回调函数处理死亡【54】
c#·回调函数·unity引擎
__water4 小时前
『功能项目』眩晕图标显示【52】
c#·unity引擎·动画事件
__water4 小时前
『功能项目』第二职业法师的平A【57】
c#·unity引擎·魔法球伤害传递
__water7 小时前
『功能项目』战士的伤害型技能【45】
c#·unity引擎·战士职业伤害型技能
君莫愁。8 小时前
【Unity】检测鼠标点击位置是否有2D对象
unity·c#·游戏引擎
Lingbug8 小时前
.Net日志组件之NLog的使用和配置
后端·c#·.net·.netcore
咩咩觉主8 小时前
Unity实战案例全解析:PVZ 植物卡片状态分析
unity·c#·游戏引擎
Echo_Lee09 小时前
C#与Python脚本使用共享内存通信
开发语言·python·c#
__water16 小时前
『功能项目』QFrameWork框架重构OnGUI【63】
c#·unity引擎·重构背包框架
Crazy Struggle16 小时前
C# + WPF 音频播放器 界面优雅,体验良好
c#·wpf·音频播放器·本地播放器