Python: User Input to create folders

Question:

I am trying to use the following working code and convert it to user input.

rp = ‘folder_path’

list = [‘test’, ‘test2’]

for i in list:
    path = os.path.join(rp, i)
    os.mkdir(path)

Essentially, this will make a folder named “test” and “test2” in the folder_path.

Is there a way to make the list from user input?

I have tried the following (manipulating it a bunch) with no luck.

rp = ‘folder_path’

list = []

foldName = int(input(“Folder Name? “))

for i in range(0, foldName):
    path = os.path.join(rp, list)
    os.mkdir(path)
Asked By: hackerboi

||

Answers:

import os

root = 'root path'
x = input("Enter names of folders : ") ## test,test3
list = x.split(",") ## specific separator 
for i in list:
    path = os.path.join(root, i)
    os.mkdir(path)

Quick and dirty – try this .. also not sure what the int conversion is about

Answered By: Jatin Morar
Categories: questions Tags:
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.