This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author eric.snow
Recipients Roman.Evstifeev, eric.araujo, eric.smith, eric.snow, ezio.melotti, loewis, r.david.murray, ronaldoussoren, santoso.wijaya
Date 2011-08-01.21:21:59
SpamBayes Score 0.0004812
Marked as misclassified No
Message-id <>
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
        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
            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
Date User Action Args
2011-08-01 21:22:00eric.snowsetrecipients: + eric.snow, loewis, ronaldoussoren, eric.smith, ezio.melotti, eric.araujo, r.david.murray, santoso.wijaya, Roman.Evstifeev
2011-08-01 21:21:59eric.snowsetmessageid: <>
2011-08-01 21:21:59eric.snowlinkissue10395 messages
2011-08-01 21:21:59eric.snowcreate