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))
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))
How to Create a Directory in Python?
# Python program to create directory using os.mkdir() method
import os
# Directory path
dir_path = "C:/Projects/Tryouts/sample"
os.mkdir(dir_path)
print("Directory '% s' created" % dir_path)
# Directory path
dir_path2 = "C:/Projects/Tryouts/sample2"
# mode
mode = 0o666
os.mkdir(dir_path2, mode)
print("Directory '% s' created" % dir_path2)
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us