Skip to content

Latest commit

 

History

History
56 lines (36 loc) · 1.87 KB

OS_Create_directory.md

File metadata and controls

56 lines (36 loc) · 1.87 KB



Template request | Bug report | Generate Data Product

Tags: #os #snippet #python #operations

Author: Moemen Ebdelli

Description: This notebook provides instructions on how to create a directory in Python.

References:

Input

Import libraries

import os

Setup Variables

  • parent_dir: Parent Directory path -> provide an absolute or relative path
  • directory: Directory name
parent_dir = "./"
directory = "MyDir"

Model

Create Directory

# Prepare the Path
path = os.path.join(parent_dir, directory)

# Create the directory MyDir under awesome-notebooks/Python
try:
    os.mkdir(path)
    msg = "Directory " + directory + " is created under " + parent_dir
except OSError as error:
    msg = "Directory was not created  : " + str(error)

Output

Print the execution message

print(msg)