Python provides different functions and libraries for operating system related operations. Creating new directory or directories is very popular thing amongst developers. In this tutorial we will look how to create and make directory in PYthon.
Using OS Library with Mkdirs Function
Python provides os
library which is mainly used for Operating system related operations. We will use mkdirs
function by providing the directory name. In this example we will create a directory named myfile
in the current working directory.
import os os.mkdir("myfile")
Provide Absolute Path
During a directory creating given file with named will be created in the current working directory. Current working directory is the path where the application or interactive console run. This situations may cause errors some time. We can prevent this errors and use more specific directory and path by providing absolute path.
In this example we will create a directory named myfile3
in the path /home/ismail/
os.mkdir("/home/ismail/myfile3")