Path类的常用方法

System.IO命名空间下

 

#region path.getFileName  获取文件名称
            string str = @"c:\123\123.txt";
            string filename = Path.GetFileName(str);
            Console.WriteLine(filename);

            #endregion

            #region 没有扩展名        path.getfilenamewithoutextension(string str)
            string filenamewithout = Path.GetFileNameWithoutExtension(str);
            Console.WriteLine("没有扩展名的:" + filenamewithout); 
            #endregion

            #region 获取文件的扩展名  path.getextension
            string ss = Path.GetExtension(str);
            Console.WriteLine("获取的扩展名"+ss);
            #endregion

            #region path.getfullpath 获取文件的绝对路径
            //string aa=Path.GetFullPath("练习4Path类操作.exe");

            string bb = Path.GetFullPath("1.exe");
            Console.WriteLine("绝对路径:"+bb);
            #endregion

            #region  path.combine 将字符串数组合并成路径
            string strtest = Path.Combine("c:\\", "1.jpg");
            Console.WriteLine(strtest);
            #endregion

 

posted @ 2014-04-01 14:08  我的技术控件  阅读(762)  评论(0编辑  收藏  举报