code: public static void createFolder(CmsObject cms, String rootPath) throws CmsException {
  
          CmsObject rootCms = OpenCms.initCmsObject(cms);
          rootCms.getRequestContext().setSiteRoot("");
          List<String> parents = new ArrayList<String>();
          String currentPath = rootPath;
          while (currentPath != null) {
              if (rootCms.existsResource(currentPath)) {
                  break;
              }
              parents.add(currentPath);
              currentPath = CmsResource.getParentFolder(currentPath);
          }
          parents = Lists.reverse(parents);
          for (String parent : parents) {
              try {
                  rootCms.createResource(
                      parent,
                      OpenCms.getResourceManager().getResourceType(CmsResourceTypeFolder.getStaticTypeName()));
                  try {
                      rootCms.unlockResource(parent);
                  } catch (CmsException e) {
                      // may happen if parent folder is locked also
                      if (LOG.isInfoEnabled()) {
                          LOG.info(e);
                      }
                  }
              } catch (CmsVfsResourceAlreadyExistsException e) {
                  // nop
              }
          }
      }
docs: Creates a folder and its parent folders if they don't exist.<p>
  
  @param cms the CMS context to use
  @param rootPath the folder root path
  
  @throws CmsException if something goes wrong