首先要弄清你对“当前目录”(Current Directory)的定义是什么。
◆工作目录
你的应用程序正在哪个目录下工作。这个目录并不一定是EXE文件所在的目录,而且在程序运行中是可以改变的。
System.IO.Directory类提供了GetCurrentDirectory方法,该方法是对Win32 API的GetCurrentDirectory函数的一个封装。
此外,System.Environment类提供了CurrentDirectory属性,由于该属性内部调用的就是System.IO.Directory.GetCurrentDirectory(),因此二者是等价的。
最后还有一个方法:
System.IO.Path.GetFullPath(".\\")
◆被执行的EXE文件所在的目录。
如果是WinForm,可以使用System.Windows.Forms.Application类提供的StartupPath属性。
此外,AppDomain.BaseDirectory属性也可以获得EXE文件所在的目录。

相关文章:

  • 2022-12-23
  • 2022-03-06
  • 2021-09-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-11-23
  • 2022-12-23
猜你喜欢
  • 2021-06-15
  • 2021-08-09
  • 2021-08-14
相关资源
相似解决方案