Reputation: 1748
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.
Upvotes: 0
Views: 748
Reputation: 5634
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.
Upvotes: 3