views:

700

answers:

2

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#?

+1  A: 

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.

Joey
+2  A: 

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.

Ryan Emerle
That worked a treat!
Danielb