C 使用path獲取檔案路徑

2021-08-10 05:38:48 字數 1359 閱讀 7522

using system.io;

path類的靜態方法:  

changeextension 更改路徑字串的副檔名。

combine(string()) 將字串陣列組合成乙個路徑。

combine(string, string) 將兩個字串組合成乙個路徑。

combine(string, string, string) 將三個字串組合成乙個路徑。

combine(string, string, string, string) 將四個字串組合成乙個路徑。

getdirectoryname 返回指定路徑字串的目錄資訊。

getextension 返回指定的路徑字串的副檔名。

getfilename 返回指定路徑字串的檔名和副檔名。

getfilenamewithoutextension 返回不具有副檔名的指定路徑字串的檔名。

getfullpath 返回指定路徑字串的絕對路徑。

getinvalidfilenamechars 獲取包含不允許在檔名中使用的字元的陣列。

getinvalidpathchars 獲取包含不允許在路徑名中使用的字元的陣列。

getpathroot 獲取指定路徑的根目錄資訊。

getrandomfilename 返回隨機資料夾名或檔名。

gettempfilename 建立磁碟上唯一命名的零位元組的臨時檔案並返回該檔案的完整路徑。

gettemppath 返回當前使用者的臨時資料夾的路徑。

ha***tension 確定路徑是否包括副檔名。

ispathrooted 獲取指示指定的路徑字串是否包含根的值。

程式例項:

static void main(string args)

", path.getdirectoryname(mypath));

console.writeline("路徑副檔名:", path.getextension(mypath));

console.writeline("檔名:", path.getfilename(mypath));

console.writeline("不帶副檔名的名稱:", path.getfilenamewithoutextension(mypath));

console.writeline("絕對全路徑:", path.getfullpath(mypath));

console.writeline("根目錄:", path.getpathroot(mypath));

console.writeline("不帶根目錄的路徑:", path.getfullpath(mypath).remove(0, 3));

console.readkey();

}

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 不同目錄分兩種情況 相對路徑只能相對於應用程式的...

C 獲取檔案路徑

string files system.io.directory.getfiles path 返回指定目錄下的檔名 string str system.io.path.getfilenamewithoutextension path 返回不具有副檔名的指定路徑字串的檔名 3 system.io.pa...