Answers for "python create directories"

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
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 add directory to python script

import os

# List all files in a directory using scandir()
basepath = 'my_directory/'
with os.scandir(basepath) as entries:
    for entry in entries:
        if entry.is_file():
            print(entry.name)
Posted by: Guest on June-17-2020
-1

how to add directory to python script

from pathlib import Path

basepath = Path('my_directory/')
files_in_basepath = basepath.iterdir()
for item in files_in_basepath:
    if item.is_file():
        print(item.name)
Posted by: Guest on June-17-2020

Code answers related to "python create directories"

Python Answers by Framework

Browse Popular Code Answers by Language