Directory.GetCurrentDirectory () not working with linux?

So, I'm trying to create an application that requires reading scripts in a subfolder called "scripts". My code I have problems with:

string script = Console.ReadLine(); string path = Directory.GetCurrentDirectory(); string sciptpath = path + "/scripts/" + script; 

This works great on Windows. But on Linux (running using Mono Runtime), it goes to the current users home directory ... not to the executable file directory. This is mistake? And can anyone suggest a workaround?

+7
source share
1 answer

It’s not that he needs to β€œfix” that the current directory is not the one you think so. The current directory is a directory that has a "focus" for relative paths. No matter where your EXE is located, your current directory may be anywhere else, or it may even change at runtime.

What would you like:

 string path = Path.GetDirectoryName(Application.ExecutablePath); 
+11
source

All Articles