您的位置:首页 > 编程语言 > C#

C# 获取文件名及扩展名

2017-09-20 10:04 288 查看
http://blog.csdn.net/houxingding/article/details/17484339

 FileStream fileStream = new FileStream(@txtPath.Text, FileMode.Open);
//txtPath.Text是文件路径

            string fileName = fileStream.Name.Substring(
                fileStream.Name.LastIndexOf("\\") + 1);  
            //获取包含扩展名的文件名 

            string aLastName = fileStream.Name.Substring(
                fileStream.Name.LastIndexOf(".") + 1);
            //获取扩展名

            string Name=fileStream.Name.Substring(
                fileStream.Name.LastIndexOf("\\") + 1
                , fileStream.Name.LastIndexOf(".")
                - fileStream.Name.LastIndexOf("\\") - 1);
            //获取不包含扩展名的文件名
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: