Os Remove
# Python2.x Python os.remove() Method
[ Python OS File/Directory Methods](#)
* * *
### Overview
The os.remove() method is used to delete a file at a specified path. If the specified path is a directory, an OSError will be raised.
This method is identical to [unlink()](#).
Valid on Unix, Windows
### Syntax
The syntax for the **remove()** method is as follows:
os.remove(path)
### Parameters
* **path** -- The path of the file to be removed.
### Return Value
This method does not return any value.
### Example
The following example demonstrates the use of the remove() method:
#!/usr/bin/python# -*- coding: UTF-8 -*-import os, sys # List directoryprint "Directory: %s" %os.listdir(os.getcwd())# Remove os.remove("aa.txt")# List directory after removalprint "After removal: %s" %os.listdir(os.getcwd())
The output of executing the above program is:
Directory: [ 'a1.txt','aa.txt','resume.doc' ]After removal: [ 'a1.txt','resume.doc' ]
[ Python OS File/Directory Methods](#)
YouTip