code: private String getTargetName(CmsResource source, CmsResource target) throws CmsException {
  
          String name;
          String folderRootPath = target.getRootPath();
          if (!folderRootPath.endsWith("/")) {
              folderRootPath += "/";
          }
          if (folderRootPath.equals(CmsResource.getParentFolder(source.getRootPath()))) {
              name = OpenCms.getResourceManager().getNameGenerator().getCopyFileName(
                  getRootCms(),
                  folderRootPath,
                  source.getName());
          } else {
              name = source.getName();
          }
          return name;
      }
docs: Gets a name for the target resource.<p>
  
  @param source Source
  @param target Target
  @return Name
  @throws CmsException exception