开发者

Running SFX from Application: Change working directory

I have an appli开发者_StackOverflow中文版cation that starts an SFX (self-extracting executable) file and extracts it.

The input file is located at c:\sfx\sfx.exe but it currently extracts to my application's start up folder (c:\myapp\,) rather than where it is stored (c:\sfx\.)

How can I alter where the output goes?


When you start an application, the 'working directory' is the directory from which you start it (unless explicitly specified otherwise.) You can change this, however, using SetCurrentDirectory of the Directory class.

An example from the referenced MSDN page:

string dir = @"C:\test";        
try
{
    //Set the current directory.
    Directory.SetCurrentDirectory(dir);
}
catch (DirectoryNotFoundException e)
{
    Console.WriteLine("The specified directory does not exist. {0}", e);
}
// Print to console the results.
Console.WriteLine("Root directory: {0}", Directory.GetDirectoryRoot(dir));
Console.WriteLine("Current directory: {0}", Directory.GetCurrentDirectory());
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜