Answers for "How could you use the os module to create a series of directories and subdirectories?"

3

create a directory python

#creates a directory without throwing an error
import os
def create_dir(dir):
  if not os.path.exists(dir):
    os.makedirs(dir)
    print("Created Directory : ", dir)
  else:
    print("Directory already existed : ", dir)
  return dir
Posted by: Guest on July-25-2020
2

create directory in python

import os
directory = "Krishna"
path_dir = "C:/Users/../Desktop/current_dir/"
if not os.path.exists(directory):
	os.mkdir(os.path.join(path_dir, directory))
Posted by: Guest on November-25-2020

Code answers related to "How could you use the os module to create a series of directories and subdirectories?"

Python Answers by Framework

Browse Popular Code Answers by Language