Python os.unlink() Method
Advertisements
Description
The method unlink() removes (deletes) the file path.If the path is a directory, OSError is raised.
Syntax
Following is the syntax for unlink() method −
os.unlink(path)
Parameters
path − This is the path, which is to be removed.
Return Value
This method does not return any value.
Example
The following example shows the usage of unlink() method.
# !/usr/bin/python
import os, sys
# listing directories
print "The dir is: %s" %os.listdir(os.getcwd())
os.unlink("aa.txt")
# listing directories after removing path
print "The dir after removal of path : %s" %os.listdir(os.getcwd())
When we run above program, it produces following result −
The dir is: [ 'a1.txt','aa.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ] The dir after removal of path : [ 'a1.txt','resume.doc','a3.py','tutorialsdir','amrood.admin' ]
python_files_io.htm
Advertisements