fixed semantics of commonprefix to work by path elements instead of

characters.
This commit is contained in:
Skip Montanaro 2000-07-12 16:55:57 +00:00
parent 03657cfdb0
commit 97bc98aea7
4 changed files with 53 additions and 12 deletions

View file

@ -118,14 +118,21 @@ def dirname(p):
def commonprefix(m):
"Given a list of pathnames, returns the longest common leading component"
if not m: return ''
prefix = m[0]
for item in m:
n = m[:]
for i in range(len(n)):
n[i] = n[i].split(os.sep)
# if os.sep didn't have any effect, try os.altsep
if os.altsep and len(n[i]) == 1:
n[i] = n[i].split(os.altsep)
prefix = n[0]
for item in n:
for i in range(len(prefix)):
if prefix[:i+1] <> item[:i+1]:
prefix = prefix[:i]
if i == 0: return ''
break
return prefix
return os.sep.join(prefix)
# Get size, mtime, atime of files.