Norfeldt
Norfeldt

Reputation: 9708

PyInstaller: drag-and-drop files to the --onefile exe

I finally got the PyInstaller up and running. So far it looks good, I'm able to create a single exe that does some calculations on the files in the directory where the exe is located. So I just copy the exe to a folder with the files I need to work on and double click the exe (windows 7).

But would it be possible to make an .exe were I just drag-and-drop my files onto and then it will calculate on those files ____?

Upvotes: 2

Views: 2962

Answers (2)

Pedro Lobito
Pedro Lobito

Reputation: 99011

Late answer (5Y), but if you drop a file into an exe created with pyinstaller, sys.argv will receive a list containing the path of all the files dragged.
The first item ([0]) is the path of the exe, i.e.:

import sys
print(sys.argv)
['C:/name_of.exe', 'C:/the_file_dragged1', , 'C:/the_file_dragged2']

Upvotes: 4

bru
bru

Reputation: 24

There is a simple way to see how the files you drop on an executable get handled: build an exe from a file with such content:

import sys
def __main__():
    with open("parameters.log", "ab") as f:
        f.write(str(sys.argv))

Use it with one or more files that you drag and drop and observe the content of parameters.log: you should find that for each file its absolute path is passed as an argument. nth file will have its path in sys.argv[n].

This can actually be generalised to any executable.

Upvotes: 1

Related Questions