0

So, I have a simple console app which takes one parameter: filename.

Now, when I run it like this:

program.exe "C:\Temp\list.json"

It works since I have passed a full file path.

What I want to achieve is next: I want to CD into C:\Temp and from there I want to call a file like:

"C:\Program Files\WS\program.exe" list.json

Basically, I want to pass in only the file name and from that construct the full file path.

How is this achievable?

I tried finding out if I can get the current directory from Terminal where I am, in my case, it would be C:Temp, but I did not find any answers for that.

DiplomacyNotWar
  • 31,605
  • 6
  • 57
  • 75
Vulovic Vukasin
  • 1,640
  • 2
  • 21
  • 30

1 Answers1

1

You can do that.

When you execute the below commands:

CD c:\TEMP
"C:\Program Files\WS\program.exe" list.json

The current directory for your program.exe would be C:\TEMP.

You can construct full path using below c# code.

//// assuming fileName contains the input file name
var fullPath = Path.Combine(Environment.CurrentDirectory, fileName);

Hope this works.

Reference: Stackoverflow Question.

Manoj Choudhari
  • 4,636
  • 2
  • 18
  • 31