Limits of sys.argv on Windows and ways to work around them?

81 Views Asked by At

I'm on Python 3.10.7 and Windows 10

Long story short: Is it possible to either increase the maximum size of sys.argv or work around it?

I'm not asking if Python can ignore the limit, I'm asking if it can be worked around if not increased. Like somehow programmatically splitting arguments into multiple appropriate-length ones, make it use relative paths instead of absolutes to make it shorter therefore allow more files at least etc etc, those sort of tricks.

I want to drag-drop files on a python script and do [stuff] to the files, but if there are too many files the character size of sys.argv goes beyond the limit and nothing happens instead of running the script, annoyance ensues.

The length of sys.argv is limited by OS restraints rather than by Python, that much I know. I can't however find what the limits are on specifically Windows, nor more importantly what, if anything, can be done to work around the limit or increase the limit.

I'm converting a large amount of images to jpeg xl all over the computer so the flexibility of drag-dropping is vital, and argv seems to be the only gateway to accessing the dropped files.

I don't believe the actual script is relevant but here's a pastebin of it anyway: https://pastebin.com/thTxqeh2

The only relevant line is

files = sys.argv[1:]

And that's as plain as can be

~Post suggestions addition~

Doing a GUI as suggested worked great, did one using PySimpleGUIQt (needed to be Qt version of PSG, the only one with any drag-drop support currently) and tested with 1000+ files and it functioned, in the same folder that could only do about 200-250 at once using argv before hitting the limit

0

There are 0 best solutions below