Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python: User Input to create folders

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)

Any help or links to solutions/study materials on the issue would be greatly appreciated! Thanks!

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading