C 中獲取程式當前路徑的7種常用的方法

2021-06-02 06:39:31 字數 1013 閱讀 8842

string str1 =process.getcurrentprocess().mainmodule.filename;//可獲得當前執行的exe的文件名。

string str2=environment.currentdirectory;//獲取和配置當前目錄(即該程序從中啟動的目錄)的完全限定路徑。

//備註 按照定義,假如該程序在本地或網路驅動器的根目錄中啟動,則此屬性的值為驅動器名稱後跟乙個尾部反斜槓(如"c:/")。假如該程序在子目錄中啟動,則此屬性的值為不帶尾部反斜槓的驅動器和子目錄路徑(如"c:/mysubdirectory")。

string str1 =process.getcurrentprocess().mainmodule.filename;//可獲得當前執行的exe的文件名。

string str2=environment.currentdirectory;//獲取和配置當前目錄(即該程序從中啟動的目錄)的完全限定路徑。

//備註 按照定義,假如該程序在本地或網路驅動器的根目錄中啟動,則此屬性的值為驅動器名稱後跟乙個尾部反斜槓(如"c:/")。假如該程序在子目錄中啟動,則此屬性的值為不帶尾部反斜槓的驅動器和子目錄路徑(如"c:/mysubdirectory")。

string str3=directory.getcurrentdirectory();//獲取應用程式的當前工作目錄。

1.   system.diagnostics.process.getcurrentprocess().mainmodule.filename獲取模組的完整路徑。

2.   system.environment.currentdirectory獲取和配置當前目錄(該程序從中啟動的目錄)的完全限定目錄。

3.   system.io.directory.getcurrentdirectory()獲取應用程式的當前工作目錄。這個不一定是程式從中啟動的目錄啊,有可能程式放在c:/www裡,這個函式有可能返回c:/documents and settings/zyb/,或c:/program files/adobe/,有時不一定返回什麼東東,我也搞不懂了。

C 中獲取程式當前路徑的7種常用的方法

c 中獲取程式當前路徑的7種最常用的方法 string str1 process.getcurrentprocess mainmodule.filename 可獲得當前執行的exe的檔名。string str2 environment.currentdirectory 獲取和設定當前目錄 即該程序從...

獲取程式當前路徑

expandfilename 返回檔案的全路徑 含驅動器 路徑 extractfileext 從檔名中抽取副檔名 extractfilename 從檔名中抽取不含路徑的檔名 extractfilepath 從檔名中抽取路徑名 extractfiledir 從檔名中抽取目錄名 extractfiled...

C 獲取當前路徑的7種方法

c 獲取當前路徑的方法如下 1.system.diagnostics.process.getcurrentprocess mainmodule.filename 獲取模組的完整路徑。2.system.environment.currentdirectory 獲取和設定當前目錄 該程序從中啟動的目錄 ...