Home > Article > Backend Development > Python solution to error when deleting a folder using os.remove
os.remove cannot be used to delete folders, otherwise access will be denied.
# -*- coding:utf-8 -*-import osif __name__ == "__main__": os.remove('D:\\test')
Running result:
Delete empty directories:
# -*- coding:utf-8 -*-import osif __name__ == "__main__": os.rmdir('D :\\test')
If the directory is not empty, an error will be reported, as follows:
Delete the directory (regardless of whether the directory is empty):
# -*- coding:utf-8 -*-import shutilif __name__ == "__main__": shutil.rmtree('D:\\test')
The above Python uses os.remove The solution to the error when deleting a folder is all the content shared by the editor. I hope it can give you a reference, and I hope you will support PHP Chinese website more.
For more Python related articles on how to solve the error when deleting a folder when using os.remove, please pay attention to the PHP Chinese website!