Answers for "how to create python file in a directory linux"

3

create a directory python

#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
Posted by: Guest on July-25-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

Code answers related to "how to create python file in a directory linux"

Python Answers by Framework

Browse Popular Code Answers by Language