Answers for "create folder in python"

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
14

create folder python

import os

# define the name of the directory to be created
path = "/tmp/year"

try:
    os.mkdir(path)
except OSError:
    print ("Creation of the directory %s failed" % path)
else:
    print ("Successfully created the directory %s " % path)
Posted by: Guest on April-19-2020
0

create folders in python

newpath = 'C:\Program Files\arbitrary' 
if not os.path.exists(newpath):
    os.makedirs(newpath)
Posted by: Guest on June-03-2021
2

creating a new folder in python

newpath = r'C:\Program Files\arbitrary' 
if not os.path.exists(newpath):
    os.makedirs(newpath)
Posted by: Guest on February-15-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
1

How to Create a Directory in Python?

# Python program to create directory using os.makedirs() method

import os

# Directory path
dir_path = "C:/Projects/Tryouts/test/sample/mydir"
os.makedirs(dir_path)
print("Directory '% s' created" % dir_path)


# Directory path
dir_path2 = "C:/Projects/Tryouts/test/sample/mydir2"
# mode
mode = 0o666
os.makedirs(dir_path2, mode)
print("Directory '% s' created" % dir_path2)
Posted by: Guest on September-25-2021

Python Answers by Framework

Browse Popular Code Answers by Language