Danielb
Danielb

Reputation: 1648

Command Line CD (Change Directory) variant in C#?

I want to write a simple C# console application to change the current directory of the command line to a directory the application works out. Looking through MSDN System.IO.Directory.SetCurrentDirectory looks ideal for this until I saw in the remarks that:

'When the application terminates, the working directory is restored to its original location (the directory where the process was started).'

And sure enough when I tried this in a test application it didn't work. Does anyone have any idea how to implement a CD variant in C#?

Upvotes: 4

Views: 2130

Answers (2)

Ryan Emerle
Ryan Emerle

Reputation: 15811

You could write a wrapper batch script:

@ECHO OFF
FOR /F "tokens=*" %%i in ('someapp.exe') do SET TOOLOUTPUT=%%i 
CD %TOOLOUTPUT%

I haven't tested this, but it should get you where you are trying to go.

Upvotes: 3

Joey
Joey

Reputation: 354506

I doubt that is possible, as you are just setting the current working directory for your program instead of the cmd process that spawned it.

Upvotes: 1

Related Questions