How to Create Directory If it Does Not Exist using Python? Last Updated : 28 Nov, 2021 Comments Improve Suggest changes Like Article Like Report In this article, We will learn how to create a Directory if it Does Not Exist using Python. Method 1: Using os.path.exists() and os.makedirs() methods Under this method, we will use exists() method takes path of demo_folder as an argument and returns true if the directory exists and returns false if the directory doesn't exist. makedirs() method is used to create demo_folder directory recursively .i.e. while creating demo_folder if any intermediate-level directory is missing then it will create all those intermediate missing directories. in the above case if the geeks_dir is not present then it will first create geeks_dir then it will create demo_folder Directory Used: Python3 import os # checking if the directory demo_folder # exist or not. if not os.path.exists("path/to/demo_folder"): # if the demo_folder directory is not present # then create it. os.makedirs("path/to/demo_folder") Output: Method 2: Using isdir() and makedirs() In this method, we will use isdir() method takes path of demo_folder2 as an argument and returns true if the directory exists and return false if the directory doesn't exist and makedirs() method is used to create demo_folder2 directory recursively .i.e. while creating demo_folder2 if any intermediate-level directory is missing then it will create all those intermediate missing directories. in the above case if the geeks_dir is not present then it will first create geeks_dir then it will create demo_folder2. Directory Used: Python3 import os # checking if the directory demo_folder2 # exist or not. if not os.path.isdir("path/to/demo_folder2"): # if the demo_folder2 directory is # not present then create it. os.makedirs("path/to/demo_folder2") output: Comment More infoAdvertise with us Next Article How to Create Directory If it Does Not Exist using Python? P pulamolusaimohan Follow Improve Article Tags : Python Python directory-program Practice Tags : python Similar Reads How to iterate over files in directory using Python? Iterating over files in a directory using Python involves accessing and processing files within a specified folder. Python provides multiple methods to achieve this, depending on efficiency and ease of use. These methods allow listing files, filtering specific types and handling subdirectories.Using 3 min read Get parent of current directory using Python In Python, the OS module is used to interact with the operating system. It comes under Python's standard utility modules and provides a portable way of using OS-dependent functionality. The os and os.path modules include many functions to interact with the file system. OS module provides various way 3 min read R - Check if a Directory Exists and Create if It does not Directories and sub-directories are accessed by their corresponding paths in the R Programming Language. It is easy to work with these in R and perform operations related to the creation, copy, and movement of folders and sub-folders within the system. In this article, we will see how to check if a 2 min read Python - How to Check if a file or directory exists Sometimes it's necessary to verify whether a dictionary or file exists. This is because you might want to make sure the file is available before loading it, or you might want to prevent overwriting an already-existing file. In this tutorial, we will cover an important concept of file handling in Pyt 5 min read How to Create a Directory using Node.js ? In this article, we will create a directory using NodeJS. NodeJS has Filesystem(fs) core module, which enables interacting with the file system, has Node.js fs.mkdir() method or Node.js fs.mkdirSync() method method, to create new directory /parent directory. Prerequisites:Node File SystemThe approac 3 min read How to create a duplicate file of an existing file using Python? In this article, we will discuss how to create a duplicate of the existing file in Python. Below are the source and destination folders, before creating the duplicate file in the destination folder. After a duplicate file has been created in the destination folder, it looks like the image below. For 5 min read How to Get directory of Current Script in Python? A Parent directory is a directory above another file/directory in a hierarchical file system. Getting the Parent directory is essential in performing certain tasks related to filesystem management. In this article, we will take a look at methods used for obtaining the Parent directory of the curren 4 min read How to Create a Folder if It Doesn't Exist in PHP ? We can easily create a folder in PHP, but before that, you have to check if the folder or directory already exists or not. So In this article, you will learn both to Check and Create a folder or directory in PHP. Methods: file_exists(): It is an inbuilt function that is used to check whether a file 3 min read How to create a list of files, folders, and subfolders in Excel using Python ? In this article, we will learn How to create a list of Files, Folders, and Sub Folders and then export them to Excel using Python. We will create a list of names and paths using a few folder traversing methods explained below and store them in an Excel sheet by either using openpyxl or pandas module 12 min read Make multiple directories based on a List using Python In this article, we are going to learn how to make directories based on a list using Python. Python has a Python module named os which forms the core part of the Python ecosystem. The os module helps us to work with operating system folders and other related functionalities. Although we can make fol 3 min read Like