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=class="st">"").join(*args, **kwargs) |
| 718 | |
| 719 | def join(self, *args: os.PathLike[str], abs: bool = False) -> LocalPath: |
| 720 | class="st">"""Return a new path by appending all &class="cm">#x27;args' as path |
| 721 | components. if abs=1 is used restart from root if any |
| 722 | of the args is an absolute path. |
| 723 | class="st">""" |
| 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 | class="cm"># special case for when we have e.g. strpath == class="st">"/" |
| 736 | actual_sep = class="st">"" if strpath.endswith(sep) else sep |
| 737 | for arg in strargs: |
| 738 | arg = arg.strip(sep) |
| 739 | if iswin32: |
| 740 | class="cm"># allow unix style paths even on windows. |
| 741 | arg = arg.strip(class="st">"/") |
| 742 | arg = arg.replace(class="st">"/", 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=class="st">"r", ensure=False, encoding=None): |
| 750 | class="st">"""Return an opened file with the given mode. |