C# 獲取路徑
string str1 =PRocess.GetCurrentProcess().MainModule.FileName;//獲得當前執(zhí)行的exe的文件名。string str2=Environment.CurrentDirectory;//獲取和設(shè)置當前目錄的完全限定路徑。string str3=Directory.GetCurrentDirectory();//獲取應(yīng)用程序的當前工作目錄。string str4=AppDomain.CurrentDomain.BaseDirectory;//獲取基目錄,它由程序集沖突解決程序用來探測程序集。string str5=application.StartupPath;//獲取啟動了應(yīng)用程序的可執(zhí)行文件的路徑,不包括可執(zhí)行文件的名稱。string str6=Application.ExecutablePath;//獲取啟動了應(yīng)用程序的可執(zhí)行文件的路徑,包括可執(zhí)行文件的名稱。string str7=AppDomain.CurrentDomain.SetupInformation.ApplicationBase;//獲取或設(shè)置包含該應(yīng)用程序的目錄的名稱。
“Application.StartupPath”:獲取當前應(yīng)用程序所在目錄的路徑,最后不包含“/”;“Application.ExecutablePath ”:獲取當前應(yīng)用程序文件的路徑,包含文件的名稱;“AppDomain.CurrentDomain.BaseDirectory”:獲取當前應(yīng)用程序所在目錄的路徑,最后包含“/”;“System.Threading.Thread.GetDomain().BaseDirectory”:獲取當前應(yīng)用程序所在目錄的路徑,最后包含“/”;“Environment.CurrentDirectory”:獲取當前應(yīng)用程序的路徑,最后不包含“/”;“System.IO.Directory.GetCurrentDirectory”:獲取當前應(yīng)用程序的路徑,最后不包含“/”;
新聞熱點
疑難解答