Pythonos.remove() Method
Example
Remove file of the specified path:
#Import os Library
import os
# Remove file of the specified path
print(os.remove('c:/test/test.txt'))
Try it Yourself »
Definition and Usage
The os.remove() method is used to delete a file path. This method can not delete a directory and if directory is found it will raise an OSError.
Syntax
os.remove(path, *, dir_fd=None)
Parameter Values
| Parameter | Description |
|---|---|
| path | Required.A path-like object representing a directory. The path-like object is either a string or bytes object representing a path. |
| dir_fd | Optional. Represent a directory. The default value of this parameter is None. If the path is absolute then dir_fd is ignored. |
Technical Details
| Return Value: | None |
|---|---|
| Python Version: | pre 2.6 |
| Python Change Log: | 3.3- The dir_fd argument. 3.6- Accepts a path-like object |