string 형식의 파일 경로를 이용하여 File Path와 Name을 분리합니다.
File Path와 File Name 분리
#include <iostream> namespace using std; int main() { string pullPath = "c:\\test\\test.tif"; int find = pullPath.rfind("\\") + 1; string filePath = pullPath.substr(0, find); string fileName = pullPath.substr(find, pullPath.length() - find); cout << "Folder Path : " << filePath << endl; cout << "File Name : " << fileName << endl; }
파일 확장자 바꾸기
#include <iostream> namespace using std; int main() { string filePath = "c:\\test\\test.tif"; string modExt = "ntf"; int ext = filePath.rfind("tif"); int name = filePath.rfind("\\") + 1; string dstPath = filePath.substr(0, name); dstPath += filePath.substr(name, ext - name); dstPath += modExt; cout << "Input Path : " << filePath << endl; cout << "Output Path : " << dstPath << endl; }