import os
index = ''
while True:
try:
os.makedirs('../hi'+index)
break
except:
if index:
index = '('+str(int(index[1:-1])+1)+')' # Append 1 to number in brackets
else:
index = '(1)'
pass # Go and try create file again
python os 创建文件/目录 同名处理
最新推荐文章于 2025-10-11 10:11:59 发布
此脚本使用Python实现了一个循环机制来尝试创建带有递增编号的唯一文件夹,如果文件夹已存在则自动增加括号内的数字以确保新文件夹名称的唯一性。
1467

被折叠的 条评论
为什么被折叠?



