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 seems as though your condition os.path.exists(dstPath) is matching the same renamed file multiple times. So for example, it renames test.jpg to test_1.jpg; then renames test_1.jpg to test_1_2.jpg, etc.
os.path.exists(dstPath)