c#檔案名稱/路徑處理方法

來源:互聯網
上載者:User

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

 

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.