Search code examples
windowspythonjavadrag-and-drop

What does dragging a file over another file and releasing do exactly?


I've had an idea of writing a program that's too easy to use. It would require a user to drag an image file onto the program's file (.py or .jar), then process the image and save it at the program's location.

I'm very unsure of how this actually works, but I believe it's basically the same as right-clicking the image and going to the open with section.

Opening a text file with another file through drag and drop (GIF)

In the example, what I believe might be happening is that textfile.txt is being passed to Notepad++ as arguments, but what type of argument could this be and how would one access it through python / java?


Solution

  • I believe it will call the program with the filename path of the dragged file as argument.

    eg: dragging image.jpg into script.py is equivalent to typing (command line): script.py "image.jpg"

    (Probably full paths are involved, etc...)

    you may test it with the following python script:

    import sys
    print(sys.argv)