C 多種方式獲取檔案路徑

2021-09-06 13:59:04 字數 369 閱讀 3160

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

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

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

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

c 獲取路徑方式

當時用directory.getcurrentdirectory 和environment.currentdirectory時需要注意 當使用installshield limited edition發布的桌面應用程式時,快捷方式需要指定wrokingdirectory,不然當通過快捷方式開啟程式指...

c 獲取檔案路徑

一 獲取當前檔案的路徑 1.system.diagnostics.process.getcurrentprocess mainmodule.filename 獲取模組的完整路徑,包括檔名。2.system.environment.currentdirectory 獲取和設定當前目錄 該程序從中啟動的...

C 獲取檔案路徑

1.獲取檔案路徑問題 首先確認 要查詢的檔案與可執行檔案是否在同一目錄下 同一目錄下 string filename test.txt fileinfo fi new fileinfo filename string path fi.fullname 不同目錄分兩種情況 相對路徑只能相對於應用程式的...