public static void updateAttachments(KBArticle kbArticle) {
    try {
      long folderId = kbArticle.getClassPK();

      String oldDirName = "knowledgebase/articles/" + folderId;
      String newDirName = "knowledgebase/kbarticles/" + folderId;

      DLLocalServiceUtil.addDirectory(
          kbArticle.getCompanyId(), CompanyConstants.SYSTEM, newDirName);

      String[] fileNames =
          DLLocalServiceUtil.getFileNames(
              kbArticle.getCompanyId(), CompanyConstants.SYSTEM, oldDirName);

      ServiceContext serviceContext = new ServiceContext();

      serviceContext.setCompanyId(kbArticle.getCompanyId());
      serviceContext.setScopeGroupId(kbArticle.getGroupId());

      for (String fileName : fileNames) {
        String shortFileName = FileUtil.getShortFileName(fileName);
        byte[] bytes =
            DLLocalServiceUtil.getFile(kbArticle.getCompanyId(), CompanyConstants.SYSTEM, fileName);

        DLLocalServiceUtil.addFile(
            kbArticle.getCompanyId(),
            CompanyConstants.SYSTEM_STRING,
            GroupConstants.DEFAULT_PARENT_GROUP_ID,
            CompanyConstants.SYSTEM,
            newDirName + StringPool.SLASH + shortFileName,
            0,
            StringPool.BLANK,
            serviceContext.getModifiedDate(null),
            serviceContext,
            bytes);
      }

      DLLocalServiceUtil.deleteDirectory(
          kbArticle.getCompanyId(),
          CompanyConstants.SYSTEM_STRING,
          CompanyConstants.SYSTEM,
          oldDirName);

      if (_log.isInfoEnabled()) {
        _log.info("Added attachments for " + folderId);
      }
    } catch (Exception e) {
      _log.error(e.getMessage());
    }
  }
  public static void deleteAttachmentsDirectory(long companyId) {
    try {
      String[] fileNames =
          DLLocalServiceUtil.getFileNames(
              companyId, CompanyConstants.SYSTEM, "knowledgebase/articles");

      if (fileNames.length > 0) {
        if (_log.isWarnEnabled()) {
          _log.warn("Unable to delete knowledgebase/articles");
        }

        return;
      }

      DLLocalServiceUtil.deleteDirectory(
          companyId,
          CompanyConstants.SYSTEM_STRING,
          CompanyConstants.SYSTEM,
          "knowledgebase/articles");
    } catch (Exception e) {
      _log.error(e.getMessage());
    }
  }