欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

C#文件路徑操作詳細(xì)總結(jié)

 更新時(shí)間:2014年01月15日 08:46:51   作者:  
本篇文章主要是對(duì)C#中的文件路徑操作進(jìn)行了詳細(xì)的總結(jié)介紹,需要的朋友可以過來參考下,希望對(duì)大家有所幫助

一、獲取當(dāng)前文件的路徑
1. System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
獲取模塊的完整路徑,包括文件名。

2. System.Environment.CurrentDirectory
獲取和設(shè)置當(dāng)前目錄(該進(jìn)程從中啟動(dòng)的目錄)的完全限定目錄。

3. System.IO.Directory.GetCurrentDirectory()
獲取應(yīng)用程序的當(dāng)前工作目錄。這個(gè)不一定是程序從中啟動(dòng)的目錄啊,有可能程序放在C:\www里,這個(gè)函數(shù)有可能返回C:\Documents and Settings\ZYB\,或者C:\Program Files\Adobe\,有時(shí)不一定返回什么東東,這是任何應(yīng)用程序最后一次操作過的目錄,比如你用Word打開了E:\doc\my.doc這個(gè)文件,此時(shí)執(zhí)行這個(gè)方法就返回了E:\doc了。

4. System.AppDomain.CurrentDomain.BaseDirectory
獲取程序的基目錄。

5. System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase
獲取和設(shè)置包括該應(yīng)用程序的目錄的名稱。

6. System.Windows.Forms.Application.StartupPath
獲取啟動(dòng)了應(yīng)用程序的可執(zhí)行文件的路徑。效果和2、5一樣。只是5返回的字符串后面多了一個(gè)"\"而已

7. System.Windows.Forms.Application.ExecutablePath
獲取啟動(dòng)了應(yīng)用程序的可執(zhí)行文件的路徑及文件名,效果和1一樣。

二、操作環(huán)境變量
利用System.Environment.GetEnvironmentVariable()方法可以很方便地取得系統(tǒng)環(huán)境變量,如:
System.Environment.GetEnvironmentVariable("windir")就可以取得windows系統(tǒng)目錄的路徑。

以下是一些常用的環(huán)境變量取值:

System.Environment.GetEnvironmentVariable("windir");
System.Environment.GetEnvironmentVariable("INCLUDE");
System.Environment.GetEnvironmentVariable("TMP");
System.Environment.GetEnvironmentVariable("TEMP");
System.Environment.GetEnvironmentVariable("Path");

最后貼出我進(jìn)行上面操作獲得的變量值,事先說明,本人是編寫了一個(gè)WinForm程序,項(xiàng)目文件存放于D:\Visual Studio Projects\MyApplication\LifeAssistant,編譯后的文件位于D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug,最后的結(jié)果如下:

1、 System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\LifeAssistant.exe

2、System.Environment.CurrentDirectory=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug

3、System.IO.Directory.GetCurrentDirectory()=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug

4、System.AppDomain.CurrentDomain.BaseDirectory=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\

5、 System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\

6、System.Windows.Forms.Application.StartupPath=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug

7、 System.Windows.Forms.Application.ExecutablePath=D:\Visual Studio Projects\MyApplication\LifeAssistant\bin\Debug\LifeAssistant.exe

System.Environment.GetEnvironmentVariable("windir")=C:\WINDOWS
System.Environment.GetEnvironmentVariable("INCLUDE")=C:\Program Files\Microsoft Visual Studio .NET 2003\SDK\v1.1\include\
System.Environment.GetEnvironmentVariable("TMP")=C:\DOCUME~1\zhoufoxcn\LOCALS~1\Temp
System.Environment.GetEnvironmentVariable("TEMP")=C:\DOCUME~1\zhoufoxcn\LOCALS~1\Temp
System.Environment.GetEnvironmentVariable("Path")=C:\WINDOWS\system32;C:\WINDOWS;C:\WINDOWS\System32\Wbem;C:\jdk1.5.0\bin;C:\MySQLServer5.0\bin;C:\Program Files\Symantec\pcAnywhere\;C:\Program Files\Microsoft SQL Server\80\Tools\BINN

相關(guān)文章

最新評(píng)論