[MFC] CString에서 확장자 제거 / 파일명 변경
본문 바로가기

응용 프로그램 개발/C++, MFC, Windows

[MFC] CString에서 확장자 제거 / 파일명 변경

728x90
반응형

확장자명 제거

다음과 같이 Left 혹은 Mid 를 이용하면

문자열에서 확장자명을 제거하여

파일명을 출력하거나 파일명을 바꿀 수 있다.

 

// 파일명 출력
int nPos = m_strInputPath.ReverseFind(L'.xlsx');
CString strInputPath = m_strInputPath.Left(nPos);

// 파일명 바꾸기
int nPos = m_strInputPath.ReverseFind(L'.xlsx');
CString strInputPath = m_strInputPath.Left(nPos) + _T("추가할 문자열") + L".xlsx";

 

// 파일명 출력
CString strText = "통합문서1_20201223.xlsx"; // 파일명+확장자
strText.Mid(0, strText.GetLength() - 5); // .xlsx : 점포함 5글자

 

728x90
반응형