A basename() variant which first strips the trailing slash, if present. Thus we always get the last component of the path, even for directories. path: Union[PathLike, str] e.g. >>> os.path.basename('/bar/foo') 'foo' >>> os.path.basename('/bar/foo/') '' >>>
(path)
| 791 | rmtree.avoids_symlink_attacks = _use_fd_functions |
| 792 | |
| 793 | def _basename(path): |
| 794 | """A basename() variant which first strips the trailing slash, if present. |
| 795 | Thus we always get the last component of the path, even for directories. |
| 796 | |
| 797 | path: Union[PathLike, str] |
| 798 | |
| 799 | e.g. |
| 800 | >>> os.path.basename('/bar/foo') |
| 801 | 'foo' |
| 802 | >>> os.path.basename('/bar/foo/') |
| 803 | '' |
| 804 | >>> _basename('/bar/foo/') |
| 805 | 'foo' |
| 806 | """ |
| 807 | path = os.fspath(path) |
| 808 | sep = os.path.sep + (os.path.altsep or '') |
| 809 | return os.path.basename(path.rstrip(sep)) |
| 810 | |
| 811 | def move(src, dst, copy_function=copy2): |
| 812 | """Recursively move a file or directory to another location. This is |