//================================================================== AnsiStr ExtractOneLevelUp(const AnsiStr& strFilePath) { AnsiStr strOutput = strFilePath; bool bHasLastSlash = false; char lastSlash; //Remove last forward or backward slash while((strOutput.lastChar() == '/') || (strOutput.lastChar() == '\\')) { lastSlash = strOutput.lastChar(); strOutput = strOutput.substr(0, strOutput.length() - 1); bHasLastSlash = true; } int pos = 0; //Up one level if(strOutput.rfind('/', pos)) strOutput = strOutput.substr(0, pos); else if(strOutput.rfind('\\', pos)) strOutput = strOutput.substr(0, pos); if(bHasLastSlash) strOutput += lastSlash; return strOutput; }
//================================================================== AnsiStr ExtractFilePath(const AnsiStr& fileName) { int npos; AnsiStr strOutput; if(fileName.rfind(L'/', npos) || fileName.rfind(L'\\', npos)) { strOutput = fileName.substr(0, npos+1); } return strOutput; }
//================================================================== AnsiStr ExtractFileName(const AnsiStr& strPathFileName) { int npos; AnsiStr strOutput = strPathFileName; if(strPathFileName.rfind(L'/', npos) || strPathFileName.rfind(L'\\', npos)) { strOutput = strPathFileName.substr(npos+1); } return strOutput; }
//================================================================== AnsiStr ExtractFileExt(const AnsiStr& strPathFileName) { int npos; AnsiStr strOut; if(strPathFileName.rfind('.', npos)) { strOut = strPathFileName.substr(npos+1); } return strOut; }
//================================================================== AnsiStr CreateNewFileAtRoot(const char* pExtWithDot) { AnsiStr strOutput = ps::dir::GetExePath(); int posDot; if(strOutput.rfind(L'.', posDot)) { AnsiStr temp = strOutput.substr(0, posDot); temp.appendFromT(pExtWithDot); return temp; } else return strOutput; }
//================================================================== AnsiStr ChangeFileExt(const AnsiStr& strFilePath, const AnsiStr& strExtWithDot) { AnsiStr strOut; int npos; if(strFilePath.rfind('.', npos)) { strOut = strFilePath.substr(0, npos); strOut += strExtWithDot; } else strOut = strFilePath + strExtWithDot; return strOut; }