How to add more folders on an existing folder?

I would like to add more folder on a existing folder.

I have a folder called ‘folder_One’. In this folder there are already 10 subfolders, which are numbered with 0, 1, 2..., 9. Now I want to create 10 more folders.

The name of the folder must also start after the last number of the already existing folder, i.e. If there is already folders which have the number 0, 1, 2, ..., 9, then it should start from 10, 11, 12, ..., 19.

If there are no subfolders in the folder folder_One, 10 new folders are to be created. How can I do that?

path_data = 'Data'
word = 'folder_One'
folder_length = 10

def create_folder():
    count = 0
    for startNum in range(folder_length):
        while os.path.exists(os.path.join(dir_path, word, str(startNum)):
            count += 1
            for folder in range(folder_length):
                 os.makedirs(os.path.join(dir_path, word, str(folder + count)))

        else:
            for folder in range(folder_length):
                 os.makedirs(os.path.join(dir_path, word, str(folder)))

Answer

you can use the following code:

path_data = 'Data'
word = 'folder_One'
folder_length = 10

def create_folder():
    base_path = os.path.join(path_data, word)
    init_folder = 0
    if os.path.exists(base_path):
        init_folder = max(map(lambda x: int(x), os.listdir(base_path))) + 1
    for folder in range(init_folder, init_folder + folder_length):
        os.makedirs(os.path.join(base_path, str(folder)))