Apr-14-2019, 08:05 PM
I don't understand the WinDLL part but you could try a callable object
def folder_exists(folder): enum_func = ctypes.WINFUNCTYPE(wintypes.BOOL, wintypes.HWND, wintypes.LPARAM) class Query: def __call__(self, hwnd, lParam): self.found = 0 length = ctypes.WinDLL('User32').GetWindowTextLengthW(hwnd) + 1 buf = ctypes.create_unicode_buffer(length) ctypes.WinDLL('User32').GetWindowTextW(hwnd, buf, length) if buf.value == folder: self.found += 1 return True query = Query() worker = enum_func(query) ctypes.WinDLL('User32').EnumWindows(worker, None) print(query.found) folder_exists('Downloads')