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/') '' >>> _basename
(path)
| 856 | rmtree.avoids_symlink_attacks = _use_fd_functions |
| 857 | |
| 858 | def _basename(path): |
| 859 | """A basename() variant which first strips the trailing slash, if present. |
| 860 | Thus we always get the last component of the path, even for directories. |
| 861 | |
| 862 | path: Union[PathLike, str] |
| 863 | |
| 864 | e.g. |
| 865 | >>> os.path.basename('/bar/foo') |
| 866 | 'foo' |
| 867 | >>> os.path.basename('/bar/foo/') |
| 868 | '' |
| 869 | >>> _basename('/bar/foo/') |
| 870 | 'foo' |
| 871 | """ |
| 872 | path = os.fspath(path) |
| 873 | sep = os.path.sep + (os.path.altsep or '') |
| 874 | return os.path.basename(path.rstrip(sep)) |
| 875 | |
| 876 | def move(src, dst, copy_function=copy2): |
| 877 | """Recursively move a file or directory to another location. This is |