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

相关推荐
Artech2 小时前
[MAF预定义的AIContextProvider-03]ChatHistoryMemoryProvider——赋予Agent从经验中学习的能力
ai·c#·agent·memory·maf
Scout-leaf2 天前
C#摸鱼实录——IoC与DI案例详解
c#
咕白m6252 天前
使用 C# 在 Excel 中应用多种字体样式
后端·c#
Artech2 天前
[MAF预定义的AIContextProvider-02]AgentSkillsProvider——将Agent Skills引入MAF
ai·c#·agent·agent skills·maf
2601_962072553 天前
李梦娇常识4600问|题库|打印版
sql·华为od·华为·c#·华为云·.net·harmonyos
m0_547486663 天前
《C#语言程序设计与实践》 全套PPT课件
c语言·c#·c语言程序设计
叶帆3 天前
【YFIOs】用C#开发硬件之设备上云
开发语言·unity·c#
IT方大同3 天前
(嵌入式操作系统)信号量
嵌入式硬件·c#
z落落3 天前
C# FileStream文件流读取文件
开发语言·c#
yngsqq3 天前
排版优化 异形排版
c#