Search code examples
c#command-lineexecution

C# Command line application working path


I have a command line application that resides in the system32 folder so that i can call this application from anywhere with out having to fill in the full path to the app. The app takes in one parameter which is a full file path (EX: C:\Test\Test.txt) and works fine when it takes in this parameter (EX: C:\Test>Test.exe C:\Test\test.txt).

I brake the incoming parameter apart into path and file name. I would like to be able to call the application with out filling in the full path to the file (EX: C:\Test>Test.exe test.txt) however i'm not sure how to get the current working path of "C:\Test\" to fill in my path variable when it comes in empty.

I have tried to use the following however it returns the path to the system32 folder and not "C:\Test\":

string _Path = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetEntryAssembly().Location);

Solution

  • Use GetCurrentDirectory()

     Directory.GetCurrentDirectory();