python如何根据输入值动态创建文件目录下再创建一个文件夹?

2024-09-01 07:59:18
推荐回答(1个)
回答1:

import os

basepath = os.getcwd() # 如果你想在当前路径下创建肢卖
# basepath = r"C:\\" #如果局乱你想在特定路径历腊逗下创建
d1 = input("d1:")
full1 = os.path.join(basepath, d1)
os.makedirs(full1, exist_ok=True)
d2 = input("d2:")
full2 = os.path.join(d1, d2)
os.makedirs(full2, exist_ok=True)