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

#include "stdafx.h"
#include "PathStringManager.h"

CPathStringOper::CPathStringOper(void)
{
}

CPathStringOper::~CPathStringOper(void)
{
}

CPathStringOper::GetFolderPathFromFullPath(LPCTSTR lpszFullPath)
{
 // 获取文件路径:
 // 注意不是“/”以结尾,因为使用过程中加上一个“/”容易,减去一个不容易
 CString m_strOriFileName(lpszFullPath);

 CString strPath;
    int n=m_strOriFileName.ReverseFind('//')+1;
    strPath=m_strOriFileName.Left(n);
 return strPath;
}

CPathStringOper::GetFileFullNameFromFullPath(LPCTSTR lpszFullPath)
{
 // 获取文件名:
 CString m_strOriFileName(lpszFullPath);
  
    CString strPath;
    int n=m_strOriFileName.GetLength()-m_strOriFileName.ReverseFind('//')-1;
    strPath=m_strOriFileName.Right(n);

 return strPath;
}

CPathStringOper::GetFileExtNameFromFullPath(LPCTSTR lpszFullPath)
{
    // 同理,获取文件后缀名则为:
    CString m_strOriFileName(lpszFullPath);
 
 CString strFileType;
    int n=m_strOriFileName.GetLength()-m_strOriFileName.ReverseFind('.')-1;
    strFileType=m_strOriFileName.Right(n);

 return strFileType;
}

 

 

>>> 后来发现Windows 本身就能,就提供API实现,

不过  GetFolderPathFromFullPath(LPCTSTR lpszFullPath),GetFileExtNameFromFullPath(LPCTSTR lpszFullPath) API没有

Common Dialog Box Functions

The following functions are used with common dialog boxes.

The following functions are used with common dialog boxes.

ChooseColor 
ChooseFont 
CommDlgExtendedError 
FindText
GetFileTitle 
GetOpenFileName 
GetSaveFileName 
PageSetupDlg 
PrintDlg 
PrintDlgEx 
ReplaceText 

 

short GetFileTitle(
  LPCTSTR lpszFile,  // pointer to full path and filename for file
  LPTSTR lpszTitle,  // pointer to buffer that receives filename
  WORD cbBuf         // length of buffer
);


BOOL GetOpenFileName(
  LPOPENFILENAME lpofn   // address of structure with initialization
                         // data
);


 

 

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值