当前位置: 首页>>代码示例>>Python>>正文


Python win32api.GetShortPathName方法代码示例

本文整理汇总了Python中win32api.GetShortPathName方法的典型用法代码示例。如果您正苦于以下问题:Python win32api.GetShortPathName方法的具体用法?Python win32api.GetShortPathName怎么用?Python win32api.GetShortPathName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在win32api的用法示例。


在下文中一共展示了win32api.GetShortPathName方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _get_win_folder_with_pywin32

# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import GetShortPathName [as 别名]
def _get_win_folder_with_pywin32(csidl_name):
    from win32com.shell import shellcon, shell
    dir = shell.SHGetFolderPath(0, getattr(shellcon, csidl_name), 0, 0)
    # Try to make this a unicode path because SHGetFolderPath does
    # not return unicode strings when there is unicode data in the
    # path.
    try:
        dir = unicode(dir)

        # Downgrade to short path name if have highbit chars. See
        # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
        has_high_char = False
        for c in dir:
            if ord(c) > 255:
                has_high_char = True
                break
        if has_high_char:
            try:
                import win32api
                dir = win32api.GetShortPathName(dir)
            except ImportError:
                pass
    except UnicodeError:
        pass
    return dir 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:appdirs.py

示例2: _get_win_folder_with_jna

# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import GetShortPathName [as 别名]
def _get_win_folder_with_jna(csidl_name):
    import array
    from com.sun import jna
    from com.sun.jna.platform import win32

    buf_size = win32.WinDef.MAX_PATH * 2
    buf = array.zeros('c', buf_size)
    shell = win32.Shell32.INSTANCE
    shell.SHGetFolderPath(None, getattr(win32.ShlObj, csidl_name), None, win32.ShlObj.SHGFP_TYPE_CURRENT, buf)
    dir = jna.Native.toString(buf.tostring()).rstrip("\0")

    # Downgrade to short path name if have highbit chars. See
    # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
    has_high_char = False
    for c in dir:
        if ord(c) > 255:
            has_high_char = True
            break
    if has_high_char:
        buf = array.zeros('c', buf_size)
        kernel = win32.Kernel32.INSTANCE
        if kernal.GetShortPathName(dir, buf, buf_size):
            dir = jna.Native.toString(buf.tostring()).rstrip("\0")

    return dir 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:27,代码来源:appdirs.py

示例3: _get_win_folder_with_jna

# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import GetShortPathName [as 别名]
def _get_win_folder_with_jna(csidl_name):
    import array
    from com.sun import jna
    from com.sun.jna.platform import win32

    buf_size = win32.WinDef.MAX_PATH * 2
    buf = array.zeros('c', buf_size)
    shell = win32.Shell32.INSTANCE
    shell.SHGetFolderPath(None, getattr(win32.ShlObj, csidl_name), None, win32.ShlObj.SHGFP_TYPE_CURRENT, buf)
    dir = jna.Native.toString(buf.tostring()).rstrip("\0")

    # Downgrade to short path name if have highbit chars. See
    # <http://bugs.activestate.com/show_bug.cgi?id=85099>.
    has_high_char = False
    for c in dir:
        if ord(c) > 255:
            has_high_char = True
            break
    if has_high_char:
        buf = array.zeros('c', buf_size)
        kernel = win32.Kernel32.INSTANCE
        if kernel.GetShortPathName(dir, buf, buf_size):
            dir = jna.Native.toString(buf.tostring()).rstrip("\0")

    return dir 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:27,代码来源:appdirs.py

示例4: testShortUnicodeNames

# 需要导入模块: import win32api [as 别名]
# 或者: from win32api import GetShortPathName [as 别名]
def testShortUnicodeNames(self):
        try:
            me = __file__
        except NameError:
            me = sys.argv[0]
        fname = os.path.abspath(me).lower()
        # passing unicode should cause GetShortPathNameW to be called.
        short_name = win32api.GetShortPathName(unicode(fname)).lower()
        self.failUnless(isinstance(short_name, unicode))
        long_name = win32api.GetLongPathName(short_name).lower()
        self.failUnless(long_name==fname, \
                        "Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
        self.failUnlessEqual(long_name, win32api.GetLongPathNameW(short_name).lower())
        long_name = win32api.GetLongPathNameW(short_name).lower()
        self.failUnless(type(long_name)==unicode, "GetLongPathNameW returned type '%s'" % (type(long_name),))
        self.failUnless(long_name==fname, \
                        "Expected long name ('%s') to be original name ('%s')" % (long_name, fname)) 
开发者ID:IronLanguages,项目名称:ironpython2,代码行数:19,代码来源:test_win32api.py


注:本文中的win32api.GetShortPathName方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。