C# 获取文件名及扩展名

来源:互联网 发布:淘宝号信誉查询131458 编辑:程序博客网 时间:2024/09/21 09:22


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);
            //获取不包含扩展名的文件名

原创粉丝点击