Python使用增量格式创建目录循环

Python使用增量格式创建目录循环,python,loops,directory,Python,Loops,Directory,我希望脚本基于给定的目录创建一个新目录,该目录已经具有相同的名称。这样,如果文件夹0存在,但文件夹1不存在,它将创建文件夹1并在一次目录创建时停止 import os i=1 while True: path = "Folder_{}/".format(i) os.makedirs(os.path.dirname("Folder_{}/".format(i)), exist_ok=False) if not os.path.exists(path): o

我希望脚本基于给定的目录创建一个新目录,该目录已经具有相同的名称。这样,如果文件夹0存在,但文件夹1不存在,它将创建文件夹1并在一次目录创建时停止

import os

i=1
while True:
    path = "Folder_{}/".format(i)
    os.makedirs(os.path.dirname("Folder_{}/".format(i)), exist_ok=False)
    if not os.path.exists(path):
        os.makedirs(os.path.dirname("Folder_{}/".format(i)), exist_ok=False)
    i += 1

我已经测试了上面的代码,它让我非常头疼,因为它每秒创建大约10K个目录。提前谢谢

这可能不是真实代码的副本,因为
while:
会导致语法错误。抱歉,编辑了“while True:”。我知道我在这方面没有突破,但我不能用它来编译。
import os
i=1
keepGoing=True
while keepGoing:
  path = "Folder_{}/".format(i)
  if not os.path.exists(path):
    os.makedirs(os.path.dirname("Folder_{}/".format(i)), exist_ok=False)
    keepGoing = False
  i += 1