c#檔案名稱/路徑處理方法
這篇文章主要介紹了c#檔案名稱/路徑處理方法,大家寫代碼處理檔案的時候會常用到
代碼如下:
string filePath = @"E:Randy0528中文目錄JustTest.rar";
Response.Write("檔案路徑:"+filePath);
Response.Write("<br/>更改路徑字串的副檔名。<br/>");
Response.Write(System.IO.Path.ChangeExtension(filePath, "txt"));
Response.Write("<br/>返回指定路徑字串的目錄資訊。。<br/>");
Response.Write(System.IO.Path.GetDirectoryName(filePath));
Response.Write("<br/>返回指定的路徑字串的副檔名。<br/>");
Response.Write(System.IO.Path.GetExtension(filePath));
Response.Write("<br/>返回指定路徑字串的檔案名稱和副檔名。<br/>");
Response.Write(System.IO.Path.GetFileName(filePath));
Response.Write("<br/>返回不具有副檔名的指定路徑字串的檔案名稱。<br/>");
Response.Write(System.IO.Path.GetFileNameWithoutExtension(filePath));
Response.Write("<br/>擷取指定路徑的根目錄資訊。<br/>");
Response.Write(System.IO.Path.GetPathRoot(filePath));
Response.Write("<br/>返回隨機檔案夾名或檔案名稱。<br/>");
Response.Write(System.IO.Path.GetRandomFileName());
Response.Write("<br/>建立磁碟上唯一命名的零位元組的臨時檔案並返回該檔案的完整路徑。<br/>");
Response.Write(System.IO.Path.GetTempFileName());
Response.Write("<br/>返回當前系統的臨時檔案夾的路徑。<br/>");
Response.Write(System.IO.Path.GetTempPath());
Response.Write("<br/>確定路徑是否包括副檔名。<br/>");
Response.Write(System.IO.Path.HasExtension(filePath));
Response.Write("<br/>擷取一個值,該值指示指定的路徑字串是包含絕對路徑資訊還是包含相對路徑資訊。<br/>");
Response.Write(System.IO.Path.IsPathRooted(filePath));
檔案路徑:E:Randy0528中文目錄JustTest.rar
更改路徑字串的副檔名。
E:Randy0528中文目錄JustTest.txt
返回指定路徑字串的目錄資訊。。
E:Randy0528中文目錄
返回指定的路徑字串的副檔名。
.rar
返回指定路徑字串的檔案名稱和副檔名。
JustTest.rar
返回不具有副檔名的指定路徑字串的檔案名稱。
JustTest
擷取指定路徑的根目錄資訊。
E:
返回隨機檔案夾名或檔案名稱。
ct2h5b2h.sed
建立磁碟上唯一命名的零位元組的臨時檔案並返回該檔案的完整路徑。
C:Documents and SettingsRandyLocal SettingsTemptmpAD.tmp
返回當前系統的臨時檔案夾的路徑。
C:Documents and SettingsRandyLocal SettingsTemp
確定路徑是否包括副檔名。
True
擷取一個值,該值指示指定的路徑字串是包含絕對路徑資訊還是包含相對路徑資訊。
True