1 way Python Creates a folder

0
423
folder with python
folder with python

I woke up this morning 15/09/2019 and i was building a web based application that lists, creates and deletes files from a directory using a php (hypertext preprocessor) instead using python.

Firstly I need to create the Directory and put in files which i need to list, create and delete using PHP codes but along the line i did a practical work with python scripting. So am going to show you how to create a folder with python.

Creating a folder with python code

The below codes can see you all the way to perform crucial task of creating a folder (new directory).

import os

def createFolder(directory):
    try:
        if not os.path.exists(directory):
            os.makedirs(directory)
    except OSError:
        print ('Unable to Create directory. ' +  directory +': Error')
        

# Here creates a folder (shopinson) in the current directory the this python file resides in
createFolder('./shopinson/')

the above Python Codes creates a folder called (shopinson) in the current directory the this python file resides in

LEAVE A REPLY

Please enter your comment!
Please enter your name here