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

相关文章
相关标签/搜索