'CMD Script to loop through directory containing .jpg and use filenames as CMD args for Python script
I have a Python program that accepts 3 CMD arguments made with "argparse" library. In CMD, I call it like this:
python main.py -arg1 filename.jpg -arg2 somevalue -arg3 some value
What it does with arg1 is takes this string, "filename.jpg" and searches the images\ folder, and if it finds it, it does something with it.
The images folder containes around 200 .jpg files that I want them all processed by my python main program, one by one.
I need to write a CMD script, but I've never done it and it's not easy for me to follow the documentation because it's really new to me. I tried:
for /f %%img in (images\*.jpg) do (
python main.py -arg1 %%img -arg2 somevalue -arg3 somevalue
)
But it returns an error.
I also tried for /l but got another error.
The closest I got to the solution was when I got actual python errors from the image processing library, saying it cannot find the image file it needs to load, meaning probably I got close but didn't quite extract the proper path with my CMD script.
How do I script this properly?
P.S. I store the code in "script.bat" file in my project directory, same location as python's main.py, and then run it with simply typing "script" from my project directory in CMD.
> (env) C:\Users\..\my-project-dir\script
Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
