Returns 'to' file or dir path relative to 'from' dir.
Result always uses forward slashes and has no trailing slash.
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('\\', '/');
    }
1193383
def path_for(self, *args):
        """"""
        if args and args[0].startswith(os.path.sep):
            return os.path.join(*args)
        return os.path.join(self._root_path or os.getcwd(), *args)
130870
def parse_path(root_dir):
    
    base_dir, last_dir, position = '', '', 0
    if root_dir:
        base_dir, last_dir = os.path.split(root_dir)
        position = -len(last_dir) if last_dir else 0
    return base_dir, last_dir, position
270965
def _file_path(self, dirname, filename):
        '''
        
        '''
        if not os.path.exists(dirname):
            try:
                os.makedirs(dirname)
            except KeyboardInterrupt as e:
                raise e
            except Exception:
                pass

        fpath = os.path.join(dirname, filename)

        if not os.path.exists(fpath):
            try:
                open(fpath, "w").close()
            except KeyboardInterrupt as e:
                raise e
            except Exception:
                pass

        return fpath
1132427
def get_file_path(filename, local=True, relative_to_module=None, my_dir=my_dir):
    
    # override my_dir if module is provided
    if relative_to_module is not None:
        my_dir = os.path.dirname(relative_to_module.__file__)
    user_path = result = filename
    if local:
        user_path = os.path.expanduser(filename)
        result = os.path.abspath(user_path)
        if os.path.exists(result):
            return result  # The file was found normally
    # otherwise look relative to the module.
    result = os.path.join(my_dir, filename)
    assert os.path.exists(result), "no such file " + repr((filename, result, user_path))
    return result
1259177
def complete_path(curr_dir, last_dir):
    
    if not last_dir or curr_dir.startswith(last_dir):
        return curr_dir
    elif last_dir == '~':
        return os.path.join(last_dir, curr_dir)
669505
def _file_path(self, src_path, dest, regex):
        
        m = re.search(regex, src_path)
        if dest.endswith('/') or dest == '':
            dest += '{filename}'
        names = m.groupdict()
        if not names and m.groups():
            names = {'filename': m.groups()[-1]}
        for name, value in names.items():
            dest = dest.replace('{%s}' % name, value)
        # remove starting slash so path can't be absolute
        dest = dest.strip(' /')
        if not dest:
            progress_logger.error('destination path must not resolve to be null')
            raise GrablibError('bad path')
        new_path = self.download_root.joinpath(dest)
        new_path.relative_to(self.download_root)
        return new_path
355417
def from_path(path):
        '''
        
        '''
        if os.path.isdir(path):
            return DirectoryInfo(path)

        if os.path.isfile(path):
            return FileInfo(path)

        return None
343881
def get_formatted_relative_path(self, path):
        
        if self.format_relative_path and \
                (path.startswith('./') or path.startswith('.\\')):
            return path[2:]
        else:
            return path
587072
def _get_relative_path(self, full_path):
        """"""
        try:
            rel_path = Path(full_path).relative_to(Path().absolute())
        except ValueError:
            LOG.error("%s: Couldn't find relative path of '%s' from '%s'.",
                      self.name, full_path, Path().absolute())
            return full_path
        return str(rel_path)
1166877
def subdir_path(directory, relative):
    """"""
    item_bits = directory.split(os.sep)
    relative_bits = relative.split(os.sep)
    for i, _item in enumerate(item_bits):
        if i == len(relative_bits) - 1:
            return os.sep.join(item_bits[i:])
        else:
            if item_bits[i] != relative_bits[i]:
                return None

    return None
406292
def get_directory_relative_to_git_root(directory: str):
    
    return os.path.relpath(os.path.realpath(directory), get_git_root_directory(directory))
1227312
def getFile(self, name, relative=None):
        
        if self.pathCallback is not None:
            return getFile(self._getFileDeprecated(name, relative))
        return getFile(name, relative or self.pathDirectory)
864222
def url_to_path(url):
    
    assert url.startswith('file:'), (
        "You can only turn file: urls into filenames (not %r)" % url)
    path = url[len('file:'):].lstrip('/')
    path = urllib.unquote(path)
    if _url_drive_re.match(path):
        path = path[0] + ':' + path[2:]
    else:
        path = '/' + path
    return path
277310
def relative_path(self, absolute_path, output_filename):
        """"""
        absolute_path = posixpath.join(settings.PIPELINE_ROOT, absolute_path)
        output_path = posixpath.join(settings.PIPELINE_ROOT, posixpath.dirname(output_filename))
        return relpath(absolute_path, output_path)
978124
def get_path(filename):
    
    path = abspath(filename) if os.path.isdir(filename) else dirname(abspath(filename))
    return path
1002499
def _append_slash_if_dir_path(self, relpath):
    """"""
    if self._isdir_raw(relpath):
      return self._append_trailing_slash(relpath)

    return relpath