@@ -96,6 +96,34 @@ std::string WSJCppCore::doNormalizePath(const std::string & sPath) {
9696
9797// ---------------------------------------------------------------------
9898
99+ std::string WSJCppCore::extractFilename (const std::string &sPath ) {
100+ // split path by /
101+ std::vector<std::string> vNames;
102+ std::string s = " " ;
103+ int nStrLen = sPath .length ();
104+ for (int i = 0 ; i < sPath .length (); i++) {
105+ if (sPath [i] == ' /' ) {
106+ vNames.push_back (s);
107+ s = " " ;
108+ if (i == nStrLen-1 ) {
109+ vNames.push_back (" " );
110+ }
111+ } else {
112+ s += sPath [i];
113+ }
114+ }
115+ if (s != " " ) {
116+ vNames.push_back (s);
117+ }
118+ std::string sRet ;
119+ if (vNames.size () > 0 ) {
120+ sRet = vNames[vNames.size ()-1 ];
121+ }
122+ return sRet ;
123+ }
124+
125+ // ---------------------------------------------------------------------
126+
99127std::string WSJCppCore::getCurrentDirectory () {
100128 char cwd[PATH_MAX];
101129 if (getcwd (cwd, sizeof (cwd)) == NULL ) {
@@ -275,20 +303,20 @@ bool WSJCppCore::makeDir(const std::string &sDirname) {
275303 std::cout << " FAILED create folder " << sDirname << std::endl;
276304 return false ;
277305 }
278- std::cout << " nStatus: " << nStatus << std::endl;
306+ // std::cout << "nStatus: " << nStatus << std::endl;
279307 return true ;
280308}
281309
282310// ---------------------------------------------------------------------
283311
284312bool WSJCppCore::writeFile (const std::string &sFilename , const std::string &sContent ) {
285313
286- std::ofstream f (sFilename , std::ifstream::in);
314+ // std::ofstream f(sFilename, std::ifstream::in);
315+ std::ofstream f (sFilename , std::ios::out);
287316 if (!f) {
288- std::cout << " FAILED could not create file to wtite " << sFilename << std::endl ;
317+ WSJCppLog::err ( " WSJCppCore " , " Could not create file to write ' " + sFilename + " ' " ) ;
289318 return false ;
290319 }
291-
292320 f << sContent << std::endl;
293321 f.close ();
294322 return true ;
@@ -492,3 +520,5 @@ void WSJCppLog::add(WSJCppColorModifier &clr, const std::string &sType, const st
492520 logFile << sLogMessage << std::endl;
493521 logFile.close ();
494522}
523+
524+
0 commit comments