'How to write files of the same name to a directory using Python

I would like to write files of the same name to a directory using Python. Like when downloading the same file from a browser.

I have an existing directory containing the files "aaa.py" and "aaa(1).py".

I would like to add several versions of a file named "aa.py".

The resulting directory should contain: "aaa.py" "aaa(1).py" "aa.py" "aa(1).py" "aa(2).py" etc.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source