Return a new path by appending all 'args' as path components. if abs=1 is used restart from root if any of the args is an absolute path.
(self, *args: os.PathLike[str], abs: bool = False)
| 717 | return self.new(basename="").join(*args, **kwargs) |
| 718 | |
| 719 | def join(self, *args: os.PathLike[str], abs: bool = False) -> LocalPath: |
| 720 | """Return a new path by appending all 'args' as path |
| 721 | components. if abs=1 is used restart from root if any |
| 722 | of the args is an absolute path. |
| 723 | """ |
| 724 | sep = self.sep |
| 725 | strargs = [os.fspath(arg) for arg in args] |
| 726 | strpath = self.strpath |
| 727 | if abs: |
| 728 | newargs: list[str] = [] |
| 729 | for arg in reversed(strargs): |
| 730 | if isabs(arg): |
| 731 | strpath = arg |
| 732 | strargs = newargs |
| 733 | break |
| 734 | newargs.insert(0, arg) |
| 735 | # special case for when we have e.g. strpath == "/" |
| 736 | actual_sep = "" if strpath.endswith(sep) else sep |
| 737 | for arg in strargs: |
| 738 | arg = arg.strip(sep) |
| 739 | if iswin32: |
| 740 | # allow unix style paths even on windows. |
| 741 | arg = arg.strip("/") |
| 742 | arg = arg.replace("/", sep) |
| 743 | strpath = strpath + actual_sep + arg |
| 744 | actual_sep = sep |
| 745 | obj = object.__new__(self.__class__) |
| 746 | obj.strpath = normpath(strpath) |
| 747 | return obj |
| 748 | |
| 749 | def open(self, mode="r", ensure=False, encoding=None): |
| 750 | """Return an opened file with the given mode. |