Skip to content

Instantly share code, notes, and snippets.

@ysc3839
Created December 21, 2017 08:48
Show Gist options
  • Save ysc3839/c7c30df651767865a2636fd7e93d211b to your computer and use it in GitHub Desktop.
Save ysc3839/c7c30df651767865a2636fd7e93d211b to your computer and use it in GitHub Desktop.
from ctypes import windll, create_unicode_buffer, c_void_p, c_uint, c_wchar_p
kernel32 = windll.kernel32
GlobalLock = kernel32.GlobalLock
GlobalLock.argtypes = [c_void_p]
GlobalLock.restype = c_void_p
GlobalUnlock = kernel32.GlobalUnlock
GlobalUnlock.argtypes = [c_void_p]
user32 = windll.user32
GetClipboardData = user32.GetClipboardData
GetClipboardData.restype = c_void_p
DragQueryFile = windll.shell32.DragQueryFileW
DragQueryFile.argtypes = [c_void_p, c_uint, c_wchar_p, c_uint]
CF_HDROP = 15
def get_clipboard_files():
file_list = []
if user32.OpenClipboard(None):
hGlobal = user32.GetClipboardData(CF_HDROP)
if hGlobal:
hDrop = GlobalLock(hGlobal)
if hDrop:
count = DragQueryFile(hDrop, 0xFFFFFFFF, None, 0)
for i in range(count):
length = DragQueryFile(hDrop, i, None, 0)
buffer = create_unicode_buffer(length)
DragQueryFile(hDrop, i, buffer, length + 1)
file_list.append(buffer.value)
GlobalUnlock(hGlobal)
user32.CloseClipboard()
return file_list
if __name__ == '__main__':
print(get_clipboard_files())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment