How to automatically gobble Python’s argparse path input in Windows?

  argparse, command-line, pathlib, python, windows

I’m developing some Python software foobar using argparse that takes many files as input and gobble/wildcards are very welcome. When running commands such as

foobar *.foo *.bar

in Unix Shell environments, things work just fine. In Windows, both cmd.exe and powershell fail to naturally expand these wildcards. I was wondering if I could use a bit of pathlib, which is already in the stack, to gobble any unexpanded command-line args. Is there any way to do this safely?

Note: All input args are file paths unless told otherwise via additional options. This should not be a thing to be concerned with. Running in Python 3.7+

Source: Windows Questions

LEAVE A COMMENT