반응형
std::string StoreSCPService::GetDirectoryPath(std::string filePath)
{
std::string dirPath;
const size_t last_slash_idx = filePath.rfind('\\');
if (std::string::npos != last_slash_idx)
{
dirPath = filePath.substr(0, last_slash_idx);
}
return dirPath;
}
std::string StoreSCPService::GetUniqueFilePath(std::string filePath)
{
std::string dirPath = GetDirectoryPath(filePath);
std::string fileName = base_name<std::string>(filePath);
std::string newFileName = GetUniqueFileName(filePath, fileName);
std::string newFilePath = string_format("%s%s", dirPath.c_str(), newFileName.c_str());
return newFilePath;
}
std::string StoreSCPService::GetFileExtension(const std::string& FileName)
{
if (FileName.find_last_of(".") != std::string::npos)
return FileName.substr(FileName.find_last_of(".") + 1);
return "";
}
std::string StoreSCPService::GetUniqueFileName(std::string filePath, std::string filename, int i)
{
std::string dirPath = GetDirectoryPath(filePath);
std::string name = base_name<std::string>(filePath);
std::string path = filePath;
if (name != filename)
{
path = string_format("%s%s", dirPath.c_str(), filename.c_str());
}
if (IsExist(path))
{
std::string ext = GetFileExtension(name);
size_t lastindex = name.find_last_of(".");
name = name.substr(0, lastindex);
i++;
std::string newFileName = string_format("%s_(%d).%s", name.c_str(), i, ext.c_str());
filename = GetUniqueFileName(filePath, newFileName, i);
}
return filename;
}
반응형
'[====== Development ======] > C++' 카테고리의 다른 글
[C++] CString <-> const char* 변환 (0) | 2021.11.24 |
---|---|
C++에서 Python 임베딩하기 (0) | 2021.09.17 |
[C/C++] std::string 포맷스트링(Formatted String) 구현 방법 (0) | 2021.08.06 |
File Exist Check (0) | 2021.08.06 |
[MFC] 중복실행 방지 (0) | 2021.08.04 |