Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Path of the local directory

Tags:

c#

A rather simple question; how to find the path of the local directory in which my exe is placed? As-in I have an .exe and in the program I have to create a txt file in the directory where the exe is!

[language - C#]

So, if the exe is in C:/Temp and is started from there; my txt should be created in C:/Temp

If the user wishes to move the exe to D:/Temp and runs from there; I should be able to create the txt file in D:/Temp

I tried the Directory.GetCurrentDirectory() but that returns the directory of the execution of the program!

like image 1000
Jayesh Avatar asked May 26 '10 08:05

Jayesh


People also ask

What is the path of a directory?

A path is a slash-separated list of directory names followed by either a directory name or a file name. A directory is the same as a folder.

What is a local file path?

A local path is the path to a folder or file on your local computer (e.g. C:\Program Files\Sitebulb). A UNC path is the path to a folder or file on a network and contains the server name in the path (e.g. \\server01\sitebulb\path).

How do I find the path of a directory in Linux?

To determine the exact location of your current directory within the file system, go to a shell prompt and type the command pwd. This tells you that you are in the user sam's directory, which is in the /home directory. The command pwd stands for print working directory.


1 Answers

Assembly.GetExecutingAssembly().Location

like image 167
Hans Olsson Avatar answered Sep 30 '22 00:09

Hans Olsson