Directory.GetCurrentDirectory和Application.StartupPath的區別

System.IO.Directory.GetCurrentDirectory()方法用於得到應用程序當前工做目錄。 
System.Windows.Forms.Application.StartupPath 得到應用程序的可執行文件的路徑,不含文件名 

StartupPath 可執行文件固定就不會變,可用於定位 
GetCurrentDirectory 不必定是可執行文件所在目錄,因啓動的位置而變 

若有兩個程序 C:/A/a.exe 和 C:/B/b.exe 
當在 a.exe 中啓動 b.exe,System.Diagnostics.Process.Start(@"C:/B/b.exe") 
這時,b.exe 中 Directory.GetCurrentDirectory()方法 返回值爲「C:/A」,Application.StartupPath 值爲「C:/B」 
若是直接在 C:/B/ 中啓動 b.exe,那麼兩個值就會同樣,都爲「C:/B」 
這就是 Directory.GetCurrentDirectory 和 Application.StartupPath 的區別spa

相關文章
相關標籤/搜索