Eric Snow <ericsnowcurren...@gmail.com> added the comment:

You can already get the better prefix using os.path, albeit less efficiently.  
Here's an example:

def commondirname(paths):
    subpath = os.path.commonprefix(paths)
    for path in paths:
        if path == subpath:
            return subpath
    else:
        return os.path.join(os.path.split(subpath)[0], "")

However, would it be better to implicitly normalize paths first rather than 
doing a character-by-character comparison?  Here is an unoptimized 
demonstration of what I mean:

def commondirname(paths):
    result = ""
    for path in paths:
        path = os.path.normcase(os.path.abspath(path))
        if not result:
            result = path
        else:
            while not path.startswith(result + os.path.sep):
                result, _ = os.path.split(result)
                if os.path.splitdrive(result)[1] == os.path.sep:
                    return result
    return result

----------
nosy: +ericsnow

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue10395>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to