VC 中如何从字符串中分离文件名与路径

来源:互联网 发布:plc三菱编程入门 编辑:程序博客网 时间:2024/06/11 12:59

VC 中如何从字符串中分离文件名与路径 

2008-11-05 16:22:07|  分类:程序设计 |  标签:|字号订阅

by 石头

    获取文件路径:
CString strPath;
    int n=m_strOriFileName.ReverseFind('\\')+1;
    strPath=m_strOriFileName.Left(n);

    获取文件名:
    CString strFile;
    int n=m_strUntFileName.GetLength()-m_strOriFileName.ReverseFind('\\')-1;
    strFile=m_strOriFileName.Right(n);

    同理,获取文件后缀名则为:
    CString strFileType;
    int n=m_strUntFileName.GetLength()-m_strOriFileName.ReverseFind('.')-1;
    strFileType=m_strOriFileName.Right(n);
原创粉丝点击