

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a directory using Python?
To create a directory, first check if it already exists using os.path.exists(directory). Then you can create it using:
import os if not os.path.exists('my_folder'): os.makedirs('my_folder')
You can also use the python idiom EAFP: Easier to ask for forgiveness than permission. For example,
import os try: os.makedirs('my_folder') except OSError as e: if e.errno != errno.EEXIST: raise
- Related Questions & Answers
- How to create a directory recursively using Python?
- How to create a unique directory name using Python?
- How to create a directory using Java?
- How to create a Directory using C#?
- How to create a zip archive of a directory using Python?
- How to create a Directory recursively using Java?
- How to create a directory hierarchy using Java?
- How to remove a directory using Python?
- How to remove a directory recursively using Python?
- How to calculate a directory size using Python?
- How to create a directory in project folder using Java?
- How to rename directory using Python?
- How to create a new directory in Linux using the terminal?
- How can I create a directory if it does not exist using Python?
- How to change current directory using Python?
Advertisements