2019年1月1日 星期二

[C#] 取得檔案路徑相關資訊



參考:http://rojerchen.blogspot.com/2013/02/c.html


            string file = @"d:\abc\123.txt";

            //string file = @"d:\abc\";

            string s0 = Path.GetFileName(file); //取得完整檔名 > 123.txt

            string s1 = Path.GetFileNameWithoutExtension(file); //取得檔案名,不包含副檔名,本例得到 123
           
            string s2 = Path.GetExtension(file); //取得副檔名 txt

            string s3 = Path.GetPathRoot(file); //取得根目錄 d:\a

            string s4 = Path.GetFullPath(file); //取得路徑 d:\abc\123.txt



 

MangoHost Copyright © 2009 Cookiez is Designed by Ipietoon for Free Blogger Template