How to create new folder

0 votes
I want to put output information of my program to a folder. if given folder does not exist, then the program should create a new folder with folder name as given in the program. Is this possible? If yes, please let me know how.

Suppose I have given folder path like "C:\Program Files\alex" and alex folder doesn't exist then program should create alex folder and should put output information in the alex folder.
Sep 3, 2018 in Python by bug_seeker
• 15,510 points
878 views

1 answer to this question.

0 votes

You can create a folder with os.makedirs()
and use os.path.exists() to see if it already exists:

newpath = r'C:\Program Files\arbitrary' 
if not os.path.exists(newpath):
    os.makedirs(newpath)

If you're trying to make an installer: Windows Installer does a lot of work for you.

answered Sep 3, 2018 by Priyaj
• 58,020 points

Related Questions In Python

0 votes
1 answer

How to create new environment using conda?

Hi@akhtar, Environment means you are creating your own ...READ MORE

answered Apr 21, 2020 in Python by MD
• 95,460 points
1,073 views
+2 votes
2 answers

How can I create a new file in Python?

You can try the below code which ...READ MORE

answered Mar 31, 2018 in Python by anto.trigg4
• 3,440 points
1,293 views
0 votes
1 answer

How to add a new line in Python?

You can use '\n' for a next ...READ MORE

answered May 2, 2018 in Python by aayushi
• 750 points
1,259 views
0 votes
1 answer

How to create transaction in GnuCash in response to an email?

Here's a template, along with a couple ...READ MORE

answered Sep 5, 2018 in Python by Priyaj
• 58,020 points
1,064 views
0 votes
1 answer

What is the fucntion of mkdir -p in Python

mkdir -p gives you an error if the ...READ MORE

answered Oct 30, 2018 in Python by Priyaj
• 58,020 points
926 views
0 votes
1 answer

Examples for string find in Python

you can use str.index too: >>> 'sdfasdf'.index('cc') Traceback ...READ MORE

answered Aug 29, 2018 in Python by Priyaj
• 58,020 points
790 views
0 votes
1 answer
0 votes
1 answer

Python constructors and __init__

There is no function overloading in Python, ...READ MORE

answered Oct 11, 2018 in Python by SDeb
• 13,300 points
1,105 views
0 votes
2 answers

How to create new folder?

import os try: os.makedirs(path) except ...READ MORE

answered Aug 31, 2018 in Python by Omkar
• 69,220 points
841 views
+1 vote
1 answer

How to create plots using python matplotlib in IPython notebook?

I think you should try: I used %matplotlib inline in ...READ MORE

answered Aug 8, 2018 in Python by Priyaj
• 58,020 points
1,566 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP