mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
* split on / or \
* case insensitive
This commit is contained in:
parent
d61591813c
commit
6222c05af6
1 changed files with 3 additions and 6 deletions
|
@ -107,12 +107,9 @@ def dirname(p):
|
||||||
def commonprefix(m):
|
def commonprefix(m):
|
||||||
"Given a list of pathnames, returns the longest common leading component"
|
"Given a list of pathnames, returns the longest common leading component"
|
||||||
if not m: return ''
|
if not m: return ''
|
||||||
n = m[:]
|
n = map(string.lower, m)
|
||||||
for i in range(len(n)):
|
for i in range(len(n)):
|
||||||
n[i] = n[i].split(os.sep)
|
n[i] = re.split(r"[/\\]", n[i])
|
||||||
# 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]
|
prefix = n[0]
|
||||||
for item in n:
|
for item in n:
|
||||||
|
@ -121,7 +118,7 @@ def commonprefix(m):
|
||||||
prefix = prefix[:i]
|
prefix = prefix[:i]
|
||||||
if i == 0: return ''
|
if i == 0: return ''
|
||||||
break
|
break
|
||||||
return os.sep.join(prefix)
|
return "\\".join(prefix)
|
||||||
|
|
||||||
|
|
||||||
# Get size, mtime, atime of files.
|
# Get size, mtime, atime of files.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue