Return the relative path between a parent directory and some child path

@param parent
@param child

@return the relative path for the child

@throws IllegalArgumentException if child is not a subpath
189088
public static String relativePath(File parent, File child) {
        Path superPath = parent.toPath();
        Path subPath = child.toPath();
        if (!subPath.startsWith(superPath)) {
            throw new IllegalArgumentException("Not a subpath: " + child);
        }
        return superPath.relativize(subPath).toString();
    }
849552
def relpath_for(self, path):
        """"""
        if self.parent_dir in (".", ""):
            return path

        if path == self.parent_dir:
            return ""

        dirname = os.path.dirname(path) or "."
        basename = os.path.basename(path)

        cached = self.relpath_cache.get(dirname, empty)
        if cached is empty:
            cached = self.relpath_cache[dirname] = os.path.relpath(dirname, self.parent_dir)

        return os.path.join(cached, basename)
276685
def _get_path_from_parent(self, parent):
    
    if hasattr(self, 'get_path_from_parent'):
        return self.get_path_from_parent(parent)
    if self.model is parent:
        return []
    model = self.concrete_model
    # Get a reversed base chain including both the current and parent
    # models.
    chain = model._meta.get_base_chain(parent) or []
    chain.reverse()
    chain.append(model)
    # Construct a list of the PathInfos between models in chain.
    path = []
    for i, ancestor in enumerate(chain[:-1]):
        child = chain[i + 1]
        link = child._meta.get_ancestor_link(ancestor)
        path.extend(link.get_reverse_path_info())
    return path
557742
protected Path normalizePath(final Path parent, final String path) {
        return parent.resolve(path).toAbsolutePath().normalize();
    }
7521
def _find_parent_directory(directory, filename):
        
        parent_directory = directory
        absolute_directory = '.'
        while absolute_directory != os.path.abspath(parent_directory):
            absolute_directory = os.path.abspath(parent_directory)
            if os.path.isfile(os.path.join(absolute_directory, filename)):
                return absolute_directory
            if os.path.isabs(parent_directory):
                parent_directory = os.path.join(os.path.dirname(parent_directory), '..',
                                                os.path.basename(parent_directory))
            else:
                parent_directory = os.path.join('..', parent_directory)
        return os.path.abspath(directory)
56128
public static String getRelativePath(File file, File folder) {

        String filePath = file.getAbsolutePath();
        String folderPath = folder.getAbsolutePath();

        if (filePath.startsWith(folderPath)) {
            return filePath.substring(folderPath.length() + 1);
        } else {
            return null;
        }
    }
165468
public String getRelativePath(File from, File to) {
        Path fromPath = Paths.get(from.getPath()).normalize().toAbsolutePath();
        Path toPath = Paths.get(to.getPath()).normalize().toAbsolutePath();
        return fromPath.relativize(toPath).toString().replace('\\', '/');
    }
726436
@CheckForNull
  public String relativePath(Path dir, Path file) {
    Path baseDir = dir.normalize();
    Path path = file.normalize();
    if (!path.startsWith(baseDir)) {
      return null;
    }
    try {
      Path relativized = baseDir.relativize(path);
      return FilenameUtils.separatorsToUnix(relativized.toString());
    } catch (IllegalArgumentException e) {
      return null;
    }
  }
1228253
private ArchivePath calculatePath(File root, File child) {
        String rootPath = unifyPath(root.getPath());
        String childPath = unifyPath(child.getPath());
        String archiveChildPath = childPath.replaceFirst(Pattern.quote(rootPath), "");
        return new BasicPath(archiveChildPath);
    }
477068
public static String child(Resource base, String path) {
        Resource child = base.getChild(path);
        return child != null ? child.getPath() : path;
    }
931264
public static String getParentPath(final String path) {
    final int pos = path.lastIndexOf(File.separator);
    if (pos <= 0) {
      return null;
    }
    return path.substring(0, pos);
  }
297119
function (childDirName, parentPath, parent) {
		parentPath = parentPath || "";
		if (arguments.length < 3) {
			parent = { 
				config: {},
			};
		}

		return {
			name: childDirName,
			path: path.join(parentPath, childDirName),
			parentRoute: '/' + parentPath,
			config: {},
			parent: parent,
		};
	}
218270
public Path getParent() {
    String path = uri.getPath();
    int lastSlash = path.lastIndexOf('/');
    int start = hasWindowsDrive(path, true) ? 3 : 0;
    if ((path.length() == start) ||               // empty path
        (lastSlash == start && path.length() == start+1)) { // at root
      return null;
    }
    String parent;
    if (lastSlash==-1) {
      parent = CUR_DIR;
    } else {
      int end = hasWindowsDrive(path, true) ? 3 : 0;
      parent = path.substring(0, lastSlash==end?end+1:lastSlash);
    }
    return new Path(uri.getScheme(), uri.getAuthority(), parent);
  }
40624
public static File getRelativePath(final File basePath, final File refPath) {
        if (!basePath.toPath().getRoot().equals(refPath.toPath().getRoot())) {
            return refPath;
        }
        return basePath.toPath().getParent().relativize(refPath.toPath()).toFile();
    }
1221439
private String normalizeActionPath(Resource parent, String uri) {
        String relativeUri = extractRelativeUrl(uri, parent.getUri());
        if (!relativeUri.startsWith("/")) {
            relativeUri = "/" + relativeUri;
        }
        return relativeUri;
    }
140312
public static File getRelativePath(final File relativePath) {
        final String p = getRelativePathForPath(relativePath.getPath(), File.separator);
        return p != null ? new File(p) : null;
    }
197195
public static String getPathToChild(Resource file, Resource dir) {
	if (dir == null || !file.getResourceProvider().getScheme().equals(dir.getResourceProvider().getScheme())) return null;
	boolean isFile = file.isFile();
	String str = "/";
	while (file != null) {
	    if (file.equals(dir)) {
		if (isFile) return str.substring(0, str.length() - 1);
		return str;
	    }
	    str = "/" + file.getName() + str;
	    file = file.getParentResource();
	}
	return null;
    }