Using python to make a single folder / Directory


The below codes are best and simple ways to make a folder easily using python as regards in supplement to my previous post captioned Creating a folder using Python (

How to Make a single Folder Using Python

the below codes are tested, proved and sure codes to create a single folder in python without wasting time writing bulky codes just to implement a simple task of creating just “a” folder

Code Snippet Test 1 #Example 1

import os


this code snippet throws FileExistsError if the ‘shopinson_directory‘ already exists in the current folder/directory 

Code snippet Test 2  #Example 2

from pathlib import Path

p = Path('shopinson_directory/')

this second Test 2 #Example 2 throws FileExistsError as #Example 1

Now to ignore the FileExistsError been thrown, use the below code to create  a single folder in python

from pathlib import Path

p = Path('shopinson_directory')

this FileExistsError is bypassed by defining exist_ok=True argument to .mkdir():


Please enter your comment!
Please enter your name here