def make_path_properties(file_or_path, prefix=''):
    """Build useful properties from a file path."""
    is_std = file_or_path in (sys.stdin, sys.stdout, sys.stderr)

    if is_std:
        path = '-'
    elif is_filelike(file_or_path):
        try:
            path = str(file_or_path.name)
        except AttributeError:
            path = None
    else:
        path = str(file_or_path)

    if is_std or not path:
        abspath = dirname = basename = stem = ext = None
        realpath = realdrive = realdir = realbase = realstem = realext = None
        numbers = num = None
    else:
        abspath = os.path.abspath(path)

        dirname, basename = os.path.split(path)
        stem, ext = os.path.splitext(basename)

        if not dirname:
            dirname = os.curdir

        realpath = os.path.realpath(path)
        realdrive, tail = os.path.splitdrive(realpath)
        realdir, realbase = os.path.split(tail)
        realstem, realext = os.path.splitext(realbase)

        numbers = [int(s) for s in re.findall(r'\d+', basename)]
        num = numbers[-1] if numbers else None

    return {
            prefix + 'path':      path,
            prefix + 'abspath':   abspath,
            prefix + 'dirname':   dirname,
            prefix + 'basename':  basename,
            prefix + 'stem':      stem,
            prefix + 'ext':       ext,
            prefix + 'realpath':  realpath,
            prefix + 'realdrive': realdrive,
            prefix + 'realdir':   realdir,
            prefix + 'realbase':  realbase,
            prefix + 'realstem':  realstem,
            prefix + 'realext':   realext,
            prefix + 'numbers':   numbers,
            prefix + 'num':       num,
        }
def make_path_properties ( file_or_path , prefix = '' ) : is_std = file_or_path in ( sys . stdin , sys . stdout , sys . stderr ) if is_std : path = '-' elif is_filelike ( file_or_path ) : try : path = str ( file_or_path . name ) except AttributeError : path = None else : path = str ( file_or_path ) if is_std or not path : abspath = dirname = basename = stem = ext = None realpath = realdrive = realdir = realbase = realstem = realext = None numbers = num = None else : abspath = os . path . abspath ( path ) dirname , basename = os . path . split ( path ) stem , ext = os . path . splitext ( basename ) if not dirname : dirname = os . curdir realpath = os . path . realpath ( path ) realdrive , tail = os . path . splitdrive ( realpath ) realdir , realbase = os . path . split ( tail ) realstem , realext = os . path . splitext ( realbase ) numbers = [ int ( s ) for s in re . findall ( r'\d+' , basename ) ] num = numbers [ - 1 ] if numbers else None return { prefix + 'path' : path , prefix + 'abspath' : abspath , prefix + 'dirname' : dirname , prefix + 'basename' : basename , prefix + 'stem' : stem , prefix + 'ext' : ext , prefix + 'realpath' : realpath , prefix + 'realdrive' : realdrive , prefix + 'realdir' : realdir , prefix + 'realbase' : realbase , prefix + 'realstem' : realstem , prefix + 'realext' : realext , prefix + 'numbers' : numbers , prefix + 'num' : num , }
Build useful properties from a file path.