YouTip LogoYouTip

Python3 Os Remove

# Python3.x Python3 os.remove() Method [![Image 3: Python3 OS File/Directory Methods](#) Python3 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. Effective in Unix and 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 a value. ### Example The following example demonstrates the use of the remove() method: #!/usr/bin/python3import os, sys # List directoryprint ("Directory is: %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 is: [ 'a1.txt', 'aa.txt', 'resume.doc' ] After removal: [ 'a1.txt', 'resume.doc' ] [![Image 4: Python3 OS File/Directory Methods](#) Python3 OS File/Directory Methods](#)
← Python3 Os RemovePython3 Os Read β†’