C# 获取文件名及扩展名

来源:互联网 发布:sketch 46 破解版 mac 编辑:程序博客网 时间:2024/04/30 03:08
 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);
            //获取不包含扩展名的文件名
0 0
原创粉丝点击