本文整理汇总了Python中win32file.GetFileAttributes方法的典型用法代码示例。如果您正苦于以下问题:Python win32file.GetFileAttributes方法的具体用法?Python win32file.GetFileAttributes怎么用?Python win32file.GetFileAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类win32file
的用法示例。
在下文中一共展示了win32file.GetFileAttributes方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: testMoreFiles
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetFileAttributes [as 别名]
def testMoreFiles(self):
# Create a file in the %TEMP% directory.
testName = os.path.join( win32api.GetTempPath(), "win32filetest.dat" )
desiredAccess = win32file.GENERIC_READ | win32file.GENERIC_WRITE
# Set a flag to delete the file automatically when it is closed.
fileFlags = win32file.FILE_FLAG_DELETE_ON_CLOSE
h = win32file.CreateFile( testName, desiredAccess, win32file.FILE_SHARE_READ, None, win32file.CREATE_ALWAYS, fileFlags, 0)
# Write a known number of bytes to the file.
data = str2bytes("z") * 1025
win32file.WriteFile(h, data)
self.failUnless(win32file.GetFileSize(h) == len(data), "WARNING: Written file does not have the same size as the length of the data in it!")
# Ensure we can read the data back.
win32file.SetFilePointer(h, 0, win32file.FILE_BEGIN)
hr, read_data = win32file.ReadFile(h, len(data)+10) # + 10 to get anything extra
self.failUnless(hr==0, "Readfile returned %d" % hr)
self.failUnless(read_data == data, "Read data is not what we wrote!")
# Now truncate the file at 1/2 its existing size.
newSize = len(data)//2
win32file.SetFilePointer(h, newSize, win32file.FILE_BEGIN)
win32file.SetEndOfFile(h)
self.failUnlessEqual(win32file.GetFileSize(h), newSize)
# GetFileAttributesEx/GetFileAttributesExW tests.
self.failUnlessEqual(win32file.GetFileAttributesEx(testName), win32file.GetFileAttributesExW(testName))
attr, ct, at, wt, size = win32file.GetFileAttributesEx(testName)
self.failUnless(size==newSize,
"Expected GetFileAttributesEx to return the same size as GetFileSize()")
self.failUnless(attr==win32file.GetFileAttributes(testName),
"Expected GetFileAttributesEx to return the same attributes as GetFileAttributes")
h = None # Close the file by removing the last reference to the handle!
self.failUnless(not os.path.isfile(testName), "After closing the file, it still exists!")
示例2: can_connect
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetFileAttributes [as 别名]
def can_connect(self):
return win32file.GetFileAttributes((self.ipc_path)) == \
win32file.FILE_ATTRIBUTE_NORMAL
示例3: GetFileAttributes
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetFileAttributes [as 别名]
def GetFileAttributes(self, name):
name = cygwin2nt(name)
return win32file.GetFileAttributes(name)
示例4: testImportPywin32
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetFileAttributes [as 别名]
def testImportPywin32(exepath):
out, err = runPyExe(exepath, input="""import win32con
import win32file
print('%r' % [
win32file.GetFileAttributes('.'), win32con.FILE_ATTRIBUTE_DIRECTORY])
""")
assert '16, 16' in out
示例5: is_sparse
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetFileAttributes [as 别名]
def is_sparse(path):
supported = get_sparse_files_support(path)
if not supported:
return False
if os.name == 'nt':
return bool(win32file.GetFileAttributes(path) & FILE_ATTRIBUTE_SPARSE_FILE)
return False
示例6: is_hiden
# 需要导入模块: import win32file [as 别名]
# 或者: from win32file import GetFileAttributes [as 别名]
def is_hiden(filepath):
if sys.platform.startswith('win'): # windows
return win32file.GetFileAttributes(filepath)\
& win32con.FILE_ATTRIBUTE_HIDDEN
else: # linux
return os.path.basename(filepath).startswith('.')