Python win32file.GetFileAttributes() Examples

The following are 6 code examples of win32file.GetFileAttributes(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module win32file , or try the search function .
Example #1
Source File: test_win32file.py    From ironpython2 with Apache License 2.0 5 votes vote down vote up
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!") 
Example #2
Source File: mpv.py    From trakt-scrobbler with GNU General Public License v2.0 5 votes vote down vote up
def can_connect(self):
        return win32file.GetFileAttributes((self.ipc_path)) == \
            win32file.FILE_ATTRIBUTE_NORMAL 
Example #3
Source File: WindowsServer.py    From pycopia with Apache License 2.0 5 votes vote down vote up
def GetFileAttributes(self, name):
        name = cygwin2nt(name)
        return win32file.GetFileAttributes(name) 
Example #4
Source File: test_pyexe.py    From pyexe with Apache License 2.0 5 votes vote down vote up
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 
Example #5
Source File: platform.py    From BitTorrent with GNU General Public License v3.0 5 votes vote down vote up
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 
Example #6
Source File: util.py    From bookhub with MIT License 5 votes vote down vote up
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('.')