我想製作一個腳本,使目錄(名稱輸入) ,並在剛剛創建的輸入文件夾中創建第二個目錄。Python創建用戶輸入的子目錄
import os
import sys
user_input = raw_input("Enter name: ")
user_input1 = raw_input('Enter case: ')
path = user_input
if not os.path.exists(path):
os.makedirs(path)
path = user_input1
if not os.path.exists(user_input/user_input1):
os.makedirs(path)
我得到
if not os.path.exists(user_input/user_input1):
TypeError: unsupported operand type(s) for /: 'str' and 'str'
我在做什麼錯在這裏?
我試着這樣做:
if not os.path.exists('/user_input1/user_input'):
但是,這導致它使兩個單獨的目錄沒有子目錄
你做平均'os.path.join(USER_INPUT,user_input1)'。你寫的是用'user_input1'分割(字符串)'user_input'。 – dhke