Given a list of pathnames, returns the longest common leading component
(m)
| 67 | |
| 68 | # Return the longest prefix of all list elements. |
| 69 | def commonprefix(m): |
| 70 | "Given a list of pathnames, returns the longest common leading component" |
| 71 | if not m: return '' |
| 72 | # Some people pass in a list of pathname parts to operate in an OS-agnostic |
| 73 | # fashion; don't try to translate in that case as that's an abuse of the |
| 74 | # API and they are already doing what they need to be OS-agnostic and so |
| 75 | # they most likely won't be using an os.PathLike object in the sublists. |
| 76 | if not isinstance(m[0], (list, tuple)): |
| 77 | m = tuple(map(os.fspath, m)) |
| 78 | s1 = min(m) |
| 79 | s2 = max(m) |
| 80 | for i, c in enumerate(s1): |
| 81 | if c != s2[i]: |
| 82 | return s1[:i] |
| 83 | return s1 |
| 84 | |
| 85 | # Are two stat buffers (obtained from stat, fstat or lstat) |
| 86 | # describing the same file? |
no test coverage detected