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)
评论列表
文章目录