Join two paths together taking into account leading/trailing slashes.
@param path1 the first path
@param path2 the second path
@return the joins path
186887
public static String join(final String path1, final String path2) {
        if (path1.isEmpty() && path2.isEmpty()) return "";
        if (path1.isEmpty() && !path2.isEmpty()) return path2;
        if (path2.isEmpty() && !path1.isEmpty()) return path1;
        final StringBuilder sb = new StringBuilder(DEFAULT_BUFFER_SIZE);
        sb.append(path1);
        if (sb.charAt(sb.length() - 1) == '/') sb.setLength(sb.length() - 1);
        if (path2.charAt(0) != '/') sb.append('/');
        sb.append(path2);
        return sb.toString();
    }
983285
public static String makePath(String parent, String firstChild, String... restChildren)
    {
        StringBuilder path = new StringBuilder();

        joinPath(path, parent, firstChild);

        if ( restChildren == null )
        {
            return path.toString();
        }
        else
        {
            for ( String child : restChildren )
            {
                joinPath(path, "", child);
            }

            return path.toString();
        }
    }
1192797
def iter_path_splits(path):
    
    split_path = path.split('.')
    for i in range(len(split_path)):
        p1 = join_paths(*split_path[:i])
        p2 = join_paths(*split_path[i:])
        yield p1, p2
767027
public static String createFolderPath(String path) {

        String[] pathParts = path.split("\\.");
        String path2 = "";
        for (String part : pathParts) {
            if (path2.equals("")) {
                path2 = part;
            } else {
                path2 = path2 + File.separator
                        + changeFirstLetterToLowerCase(createClassName(part));
            }
        }

        return path2;
    }
190646
public static String combinePaths(String first, String... other) {
        return Paths.get(first, other).toString();
    }
1289339
def join_paths(fnames:FilePathList, path:PathOrStr='.')->Collection[Path]:
    ""
    path = Path(path)
    return [join_path(o,path) for o in fnames]
839186
public static org.apache.hadoop.fs.Path toHadoopPath(Path path) {
		return new org.apache.hadoop.fs.Path(path.toUri());
	}
274379
static List<String> pathParts(String path) {
        String[] pathParts = path.split("/");
        List<String> parts = new ArrayList<>(pathParts.length);
        String pathSoFar = "";
        for (String pathPart : pathParts) {
            if (!pathPart.equals("")) {
                pathSoFar += "/" + pathPart;
                parts.add(pathSoFar);
            }
        }
        return parts;
    }
1306139
private function _joinPathComponents($path)
    {
        $result = null;
        foreach (func_get_args() as $p) {
            $leading = substr($p, 0, 1);
            $trailing = substr($result, -1);

            if (!empty($p) && $leading != '/' && $leading != '?' && $trailing != '/')
                $result .= '/';

            $result .= $p;
        }
        return $result;
    }
323719
def join_path(*components):
        
        if components:
            path = components[0]
            for next in components[1:]:
                path = win32.PathAppend(path, next)
        else:
            path = ""
        return path
1109346
public static List<File> pathsFiles(final String paths, final Predicate<File> predicate) {
        final List<File> files = new ArrayList<File>();
        for (final String filePathAndName : paths.split(File.pathSeparator)) {
            final File file = new File(filePathAndName);
            if (file.isDirectory()) {
                try (final Stream<Path> stream = Files.walk(file.toPath(), Integer.MAX_VALUE)) {
                    stream.map(f -> f.toFile()).filter(predicate).forEach(files::add);
                } catch (final IOException ex) {
                    throw new RuntimeException("Error walking path: " + file, ex);
                }
            } else {
                if (predicate.test(file)) {
                    files.add(file);
                }
            }
        }
        return files;
    }
778808
private static ImmutableList<String> computePathPrefixes(String path) {
    List<String> pieces = Q_NAME_SPLITTER.splitToList(path);
    ImmutableList.Builder<String> pathPrefixes = ImmutableList.builder();

    String partial = pieces.get(0); // There will always be at least 1.
    pathPrefixes.add(partial);
    for (int i = 1; i < pieces.size(); i++) {
      partial = Q_NAME_JOINER.join(partial, pieces.get(i));
      pathPrefixes.add(partial);
    }

    return pathPrefixes.build();
  }
189690
def JoinPath(self, path_segments):
    
    # For paths on Windows we need to make sure to handle the first path
    # segment correctly.
    first_path_segment = None

    if path_segments and platform.system() == 'Windows':
      # Check if the first path segment contains a "special" path definition.
      first_path_segment = path_segments[0]
      first_path_segment_length = len(first_path_segment)
      first_path_segment_prefix = None

      # In case the path start with: \\.\C:\
      if (first_path_segment_length >= 7 and
          first_path_segment.startswith('\\\\.\\') and
          first_path_segment[5:7] == ':\\'):
        first_path_segment_prefix = first_path_segment[4:6]
        first_path_segment = first_path_segment[7:]

      # In case the path start with: \\.\ or \\?\
      elif (first_path_segment_length >= 4 and
            first_path_segment[:4] in ['\\\\.\\', '\\\\?\\']):
        first_path_segment_prefix = first_path_segment[:4]
        first_path_segment = first_path_segment[4:]

      # In case the path start with: C:
      elif first_path_segment_length >= 2 and first_path_segment[1] == ':':
        first_path_segment_prefix = first_path_segment[:2]
        first_path_segment = first_path_segment[2:]

      # In case the path start with: \\server\share (UNC).
      elif first_path_segment.startswith('\\\\'):
        prefix, _, remainder = first_path_segment[2:].partition(
            self.PATH_SEPARATOR)

        first_path_segment_prefix = '\\\\{0:s}'.format(prefix)
        first_path_segment = '\\{0:s}'.format(remainder)

      if first_path_segment_prefix:
        first_path_segment, _, remainder = first_path_segment.partition(
            self.PATH_SEPARATOR)

        if not remainder:
          _ = path_segments.pop(0)
        else:
          path_segments[0] = remainder

        first_path_segment = ''.join([
            first_path_segment_prefix, first_path_segment])

      else:
        first_path_segment = None

    # We are not using os.path.join() here since it will not remove all
    # variations of successive path separators.

    # Split all the path segments based on the path (segment) separator.
    path_segments = [
        segment.split(self.PATH_SEPARATOR) for segment in path_segments]

    # Flatten the sublists into one list.
    path_segments = [
        element for sublist in path_segments for element in sublist]

    # Remove empty path segments.
    path_segments = list(filter(None, path_segments))

    if first_path_segment is None:
      path = '{0:s}{1:s}'.format(
          self.PATH_SEPARATOR, self.PATH_SEPARATOR.join(path_segments))
    else:
      path = first_path_segment
      if path_segments:
        path = '{0:s}{1:s}{2:s}'.format(
            path, self.PATH_SEPARATOR, self.PATH_SEPARATOR.join(path_segments))

    return path
720993
public static Path[] stat2Paths(FileStatus[] stats, Path path) {
    if (stats == null)
      return new Path[]{path};
    else
      return stat2Paths(stats);
  }
631
public static boolean pathEquals(String path1, String path2) {
        return cleanPath(path1).equals(cleanPath(path2));
    }
551518
public static String joinPaths(String prefix, String path, boolean generatedPath) {

		String result = null;
		if (generatedPath) {
			result = joinDomainToPath(prefix, path);
		} else {
			result = joinPaths(prefix, path);
		}
		return result;
	}
1369505
def compare_path_strings(path1, path2, path_sep='/'):
    
    if len(path2) < len(path1):
        return 0
    if path1 == path2:
        return ISFILE
    else:
        p1_parts = path1.split(path_sep)
        p2_parts = path2.split(path_sep)
        if len(p2_parts) < len(p1_parts):
            return 0
        else:
            return compare_parts(p1_parts, p2_parts)