Answers for "create a directory using python- in windows machine"

39

python create directory

# This requires Python’s OS module
import os

# 'mkdir' creates a directory in current directory.
os.mkdir('tempDir') 
# can also be used with a path, if the other folders exist.
os.mkdir('tempDir2/temp2/temp')

# 'makedirs' creates a directory with it's path, if applicable.
os.makedirs('tempDir2/temp2/temp')
Posted by: Guest on February-24-2020
0

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)
Posted by: Guest on September-25-2021

Code answers related to "create a directory using python- in windows machine"

Python Answers by Framework

Browse Popular Code Answers by Language