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 Like