Tuesday, 21 September 2021

Python: remove: delete a file

'os.remove()' method remove a file.

 

remove_a_file_1.py

import os

path = '/Users/Shared/data/myfile.txt'
os.remove(path)

 

‘os.remove’ method throws ‘IsADirectoryError’ if the path points to a directory

 

‘os.remove’ method throws ‘FileNotFoundError’, if the file is not exists.

 

 

 

Previous                                                    Next                                                    Home

No comments:

Post a Comment