All this loop could be replaced by os.mkdirs(). In fact, I think we could just make this fct check if folderName exists, if so return, otherwise call os.mkdirs().