I am trying to get the following output until a certain condition is met.
test_1.jpg test_2.jpg .. test_50.jpg
The solution (if you could remotely call
It's probably easiest to keep dstPath something like "test_%d.jpg", and just pass it a varying count:
dstPath = "test_%d.jpg" i = 1 while os.path.exists(dstPath % i): i += 1 dstPath = dstPath % i # Final name