Obtain the folder where is the executable of my application

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I want to obtain programatically the folder where the executable of my
applicationj is installed. I want that path to find other files which are
located related to the path where my application is installed. Is there
antway to do this?
For example i want to create a fileinfo object to retrieve the info of a
file which is in the same folder as the executable of my application. I have
tried to do this:

FileInfo info=new FileInfo(".\\example.txt");

the problem with this is that when i create a FileInfo object passing an
absolute path in its constructor

FileInfo info=new FileInfo("c:\\Program Files\\Folder\\File.txt");

when i try later to create another fileinfo object to get another file in
the same folder as my application executable

FileInfo info=new FileInfo(".\\anotherexample.txt"); it throws me an
exception because it cannot find "c:\Program Files\Folder\anotherExample.txt";
 
Back
Top