@@ -255,6 +255,13 @@ bool WsjcppCore::dirExists(const std::string &sDirname) {
255255// ---------------------------------------------------------------------
256256
257257std::vector<std::string> WsjcppCore::listOfDirs (const std::string &sDirname ) {
258+ WsjcppLog::warn (" listOfDirs" , " Deprecated. Use a WsjcppCore::getListOfDirs" );
259+ return WsjcppCore::getListOfDirs (sDirname );
260+ }
261+
262+ // ---------------------------------------------------------------------
263+
264+ std::vector<std::string> WsjcppCore::getListOfDirs (const std::string &sDirname ) {
258265 std::vector<std::string> vDirs;
259266 if (!WsjcppCore::dirExists (sDirname )) {
260267 return vDirs;
@@ -280,6 +287,13 @@ std::vector<std::string> WsjcppCore::listOfDirs(const std::string &sDirname) {
280287// ---------------------------------------------------------------------
281288
282289std::vector<std::string> WsjcppCore::listOfFiles (const std::string &sDirname ) {
290+ WsjcppLog::warn (" listOfFiles" , " Deprecated. Use a WsjcppCore::getListOfFiles" );
291+ return WsjcppCore::getListOfFiles (sDirname );
292+ }
293+
294+ // ---------------------------------------------------------------------
295+
296+ std::vector<std::string> WsjcppCore::getListOfFiles (const std::string &sDirname ) {
283297 std::vector<std::string> vFiles;
284298 if (!WsjcppCore::dirExists (sDirname )) {
285299 return vFiles;
@@ -396,6 +410,25 @@ bool WsjcppCore::removeFile(const std::string &sFilename) {
396410
397411// ---------------------------------------------------------------------
398412
413+ bool WsjcppCore::copyFile (const std::string &sSourceFilename , const std::string &sTargetFilename ) {
414+ if (!WsjcppCore::fileExists (sSourceFilename )) {
415+ WsjcppLog::err (" copyFile" , " File '" + sSourceFilename + " ' did not exists" );
416+ return false ;
417+ }
418+
419+ if (WsjcppCore::fileExists (sTargetFilename )) {
420+ WsjcppLog::err (" copyFile" , " File '" + sTargetFilename + " ' already exists" );
421+ return false ;
422+ }
423+
424+ std::ifstream src (sSourceFilename , std::ios::binary);
425+ std::ofstream dst (sTargetFilename , std::ios::binary);
426+ dst << src.rdbuf ();
427+ return true ;
428+ }
429+
430+ // ---------------------------------------------------------------------
431+
399432bool WsjcppCore::createEmptyFile (const std::string &sFilename ) {
400433 if (WsjcppCore::fileExists (sFilename )) {
401434 return false ;
@@ -636,6 +669,48 @@ std::string WsjcppCore::getHumanSizeBytes(long nBytes) {
636669 return std::to_string (nBytes) + " PB" ;
637670}
638671
672+ // ---------------------------------------------------------------------
673+
674+ bool WsjcppCore::recoursiveCopyFiles (const std::string& sSourceDir , const std::string& sTargetDir ) {
675+ if (!WsjcppCore::dirExists (sSourceDir )) {
676+ WsjcppLog::err (" recoursiveCopyFiles" , " Source Dir '" + sSourceDir + " ' did not exists" );
677+ return false ;
678+ }
679+
680+ if (!WsjcppCore::dirExists (sTargetDir )) {
681+ if (!WsjcppCore::makeDir (sTargetDir )) {
682+ WsjcppLog::err (" recoursiveCopyFiles" , " Could not create target dir '" + sTargetDir + " '" );
683+ return false ;
684+ }
685+ }
686+
687+ std::vector<std::string> vFiles = WsjcppCore::getListOfFiles (sSourceDir );
688+ for (int i = 0 ; i < vFiles.size (); i++) {
689+ std::string sSourceFile = sSourceDir + " /" + vFiles[i];
690+ std::string sTargetFile = sTargetDir + " /" + vFiles[i];
691+ if (!WsjcppCore::copyFile (sSourceFile , sTargetFile )) {
692+ return false ;
693+ }
694+ }
695+
696+ std::vector<std::string> vDirs = WsjcppCore::getListOfDirs (sSourceDir );
697+ for (int i = 0 ; i < vDirs.size (); i++) {
698+ std::string sSourceDir2 = sSourceDir + " /" + vDirs[i];
699+ std::string sTargetDir2 = sTargetDir + " /" + vDirs[i];
700+ if (!WsjcppCore::dirExists (sTargetDir2 )) {
701+ if (!WsjcppCore::makeDir (sTargetDir2 )) {
702+ WsjcppLog::err (" recoursiveCopyFiles" , " Could not create target subdir '" + sTargetDir2 + " '" );
703+ return false ;
704+ }
705+ }
706+
707+ if (!WsjcppCore::recoursiveCopyFiles (sSourceDir2 , sTargetDir2 )) {
708+ return false ;
709+ }
710+ }
711+ return true ;
712+ }
713+
639714// ---------------------------------------------------------------------
640715// WsjcppLog
641716
0 commit comments