Salome HOME
ADD a end user module (services.py) to help the manipulation of SALOME KERNEL service...
[modules/kernel.git] / src / Basics / Basics_DirUtils.cxx
index b9547a1da647d976c53c595219d8fade556ebf01..4ff026829a1b8fe48b786e27edb753bb2b25b3b6 100644 (file)
@@ -50,6 +50,14 @@ namespace Kernel_Utils
     return file_path;
   }
 
+  std::string GetDirName( const std::string& file_path )
+  {
+    int pos = file_path.rfind( _separator_ );
+    if ( pos >= 0 )
+      return pos < (int)file_path.size()-1 ? file_path.substr(0, pos ) : "";
+    return std::string(".");
+  }
+
   std::string GetTmpDirByEnv( const std::string& tmp_path_env )
   {
     char* val = getenv( tmp_path_env.c_str() );
@@ -164,6 +172,26 @@ namespace Kernel_Utils
     return true;
   }
 
+  //============================================================================
+  // function : IsWritable
+  // purpose  : Returns True(False) if the path is (not) writable
+  //============================================================================ 
+  bool IsWritable(const std::string& thePath) 
+  {
+#ifdef WIN32 
+    if (  GetFileAttributes (  thePath.c_str()  ) == 0xFFFFFFFF  ) { 
+      if (  GetLastError () == FILE_ATTRIBUTE_READONLY ) {
+        return false;
+      }
+    }
+#else 
+    int status = access(thePath.c_str(),W_OK); 
+    if (status != 0) return false;
+#endif
+    return true;
+  }
+
+
   //============================================================================
   // function : GetDirByPath
   // purpose  : Returns directory by path and converts it to native system format