r"""
	A pythonic wrapper around the FindFirstFile/FindNextFile win32 api.

	>>> root_files = tuple(find_files(r'c:\*'))
	>>> len(root_files) > 1
	True
	>>> root_files[0].filename == root_files[1].filename
	False

	This test might fail on a non-standard installation
	>>> 'Windows' in (fd.filename for fd in root_files)
	True

def find_files(spec):
	r"""
	A pythonic wrapper around the FindFirstFile/FindNextFile win32 api.

	>>> root_files = tuple(find_files(r'c:\*'))
	>>> len(root_files) > 1
	True
	>>> root_files[0].filename == root_files[1].filename
	False

	This test might fail on a non-standard installation
	>>> 'Windows' in (fd.filename for fd in root_files)
	True
	"""
	fd = api.WIN32_FIND_DATA()
	handle = api.FindFirstFile(spec, byref(fd))
	while True:
		if handle == api.INVALID_HANDLE_VALUE:
			raise WindowsError()
		yield fd
		fd = api.WIN32_FIND_DATA()
		res = api.FindNextFile(handle, byref(fd))
		if res == 0:  # error
			error = WindowsError()
			if error.code == api.ERROR_NO_MORE_FILES:
				break
			else:
				raise error
	# todo: how to close handle when generator is destroyed?
	# hint: catch GeneratorExit
	windll.kernel32.FindClose(handle)