“Buat folder di Python” Kode Jawaban

Direktori Buat Python

# 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') 
SkelliBoi

Buat Python Direktori

#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
Funny Farhan

Buat folder di Python

newpath = 'C:\Program Files\arbitrary' 
if not os.path.exists(newpath):
    os.makedirs(newpath)
Expensive Earthworm

Buat python folder

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)
Embarrassed Eland

Membuat folder baru di Python

newpath = r'C:\Program Files\arbitrary' 
if not os.path.exists(newpath):
    os.makedirs(newpath)
Tired Tern

Buat direktori di 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))
visualscrapper

Jawaban yang mirip dengan “Buat folder di Python”

Pertanyaan yang mirip dengan “Buat folder di Python”

Lebih banyak jawaban terkait untuk “Buat folder di Python” di Python

Jelajahi jawaban kode populer menurut bahasa

Jelajahi bahasa kode lainnya