Python win32api 模块,GetLongPathNameW() 实例源码

我们从Python开源项目中,提取了以下9个代码示例,用于说明如何使用win32api.GetLongPathNameW()

项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
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))
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
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(str(fname)).lower()
        self.failUnless(isinstance(short_name, str))
        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)==str, "GetLongPathNameW returned type '%s'" % (type(long_name),))
        self.failUnless(long_name==fname, \
                        "Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
项目:FileBot    作者:Searinox    | 项目源码 | 文件源码
def usable_path(self,newpath):
        if self.allowed_path(newpath)==True:
            if os.path.exists(newpath)==True:
                try:
                    win32api.GetLongPathNameW(win32api.GetShortPathName(newpath))
                    return True
                except:
                    return False
        return False
项目:driveboardapp    作者:nortd    | 项目源码 | 文件源码
def check_shortpathname(fn):
    lfn = win32api.GetLongPathNameW(fn)
    fn = os.path.normcase(fn)
    lfn = os.path.normcase(lfn)
    if lfn != fn:
        print("ShortPathName: Expected %s, got %s" % (fn, lfn))
        raise SystemExit(-1)
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def testShortLongPathNames(self):
        try:
            me = __file__
        except NameError:
            me = sys.argv[0]
        fname = os.path.abspath(me).lower()
        short_name = win32api.GetShortPathName(fname).lower()
        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))
项目:remoteControlPPT    作者:htwenning    | 项目源码 | 文件源码
def testLongLongPathNames(self):
        # We need filename where the FQN is > 256 - simplest way is to create a
        # 250 character directory in the cwd (except - cwd may be on a drive
        # not supporting \\\\?\\ (eg, network share) - so use temp.
        import win32file
        basename = "a" * 250
        # but we need to ensure we use the 'long' version of the
        # temp dir for later comparison.
        long_temp_dir = win32api.GetLongPathNameW(tempfile.gettempdir())
        fname = "\\\\?\\" + os.path.join(long_temp_dir, basename)
        try:
            win32file.CreateDirectoryW(fname, None)
        except win32api.error, details:
            if details.winerror!=winerror.ERROR_ALREADY_EXISTS:
                raise
        try:
            # GetFileAttributes automatically calls GetFileAttributesW when
            # passed unicode
            try:
                attr = win32api.GetFileAttributes(fname)
            except win32api.error, details:
                if details.winerror != winerror.ERROR_FILENAME_EXCED_RANGE:
                    raise

            attr = win32api.GetFileAttributes(unicode(fname))
            self.failUnless(attr & win32con.FILE_ATTRIBUTE_DIRECTORY, attr)

            long_name = win32api.GetLongPathNameW(fname)
            self.failUnlessEqual(long_name.lower(), fname.lower())
        finally:
            win32file.RemoveDirectory(fname)
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def testShortLongPathNames(self):
        try:
            me = __file__
        except NameError:
            me = sys.argv[0]
        fname = os.path.abspath(me).lower()
        short_name = win32api.GetShortPathName(fname).lower()
        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)==str, "GetLongPathNameW returned type '%s'" % (type(long_name),))
        self.failUnless(long_name==fname, \
                        "Expected long name ('%s') to be original name ('%s')" % (long_name, fname))
项目:CodeReader    作者:jasonrbr    | 项目源码 | 文件源码
def testLongLongPathNames(self):
        # We need filename where the FQN is > 256 - simplest way is to create a
        # 250 character directory in the cwd (except - cwd may be on a drive
        # not supporting \\\\?\\ (eg, network share) - so use temp.
        import win32file
        basename = "a" * 250
        # but we need to ensure we use the 'long' version of the
        # temp dir for later comparison.
        long_temp_dir = win32api.GetLongPathNameW(tempfile.gettempdir())
        fname = "\\\\?\\" + os.path.join(long_temp_dir, basename)
        try:
            win32file.CreateDirectoryW(fname, None)
        except win32api.error as details:
            if details.winerror!=winerror.ERROR_ALREADY_EXISTS:
                raise
        try:
            # GetFileAttributes automatically calls GetFileAttributesW when
            # passed unicode
            try:
                attr = win32api.GetFileAttributes(fname)
            except win32api.error as details:
                if details.winerror != winerror.ERROR_FILENAME_EXCED_RANGE:
                    raise

            attr = win32api.GetFileAttributes(str(fname))
            self.failUnless(attr & win32con.FILE_ATTRIBUTE_DIRECTORY, attr)

            long_name = win32api.GetLongPathNameW(fname)
            self.failUnlessEqual(long_name.lower(), fname.lower())
        finally:
            win32file.RemoveDirectory(fname)
项目:mac-package-build    作者:persepolisdm    | 项目源码 | 文件源码
def check_shortpathname(fn):
    lfn = win32api.GetLongPathNameW(fn)
    fn = os.path.normcase(fn)
    lfn = os.path.normcase(lfn)
    if lfn != fn:
        print("ShortPathName: Expected %s, got %s" % (fn, lfn))
        raise SystemExit(-1)