本文整理匯總了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('.')