How to use the scandir.Win32DirEntry function in scandir

To help you get started, we’ve selected a few scandir examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github benhoyt / scandir / View on Github external
handle = FindFirstFile(filename, data_p)
        if handle == INVALID_HANDLE_VALUE:
            error = ctypes.GetLastError()
            if error == ERROR_FILE_NOT_FOUND:
                # No files, don't yield anything
            raise win_error(error, path)

        # Call FindNextFile in a loop, stopping when no more files
            while True:
                # Skip '.' and '..' (current and parent directory), but
                # otherwise yield (filename, stat_result) tuple
                name = data.cFileName
                if name not in ('.', '..'):
                    yield Win32DirEntry(name, data)

                data = wintypes.WIN32_FIND_DATAW()
                data_p = ctypes.byref(data)
                success = FindNextFile(handle, data_p)
                if not success:
                    error = ctypes.GetLastError()
                    if error == ERROR_NO_MORE_FILES:
                    raise win_error(error, path)
            if not FindClose(handle):
                raise win_error(ctypes.GetLastError(), path)
github benhoyt / scandir / View on Github external
def scandir(path='.\\*'):
            for name, stat in scandir_helper(unicode(path)):
                yield Win32DirEntry(name, stat)