Python delete a file 🗑️

Published: 21 December 2020
on channel: Bro Code
29,169
955

Python delete file tutorial example explained

#python #delete #file

import os
import shutil

path = "test.txt"

try:
os.remove(path) #delete a file
#os.rmdir(path) #delete an empty directory
#shutil.rmtree(path)#delete a directory containing files
except FileNotFoundError:
print("That file was not found")
except PermissionError:
print("You do not have permission to delete that")
except OSError:
print("You cannot delete that using that function")
else:
print(path+" was deleted")

Bro Code merch store: https://teespring.com/stores/bro-code-5


On this page of the site you can watch the video online Python delete a file 🗑️ with a duration of hours minute second in good quality, which was uploaded by the user Bro Code 21 December 2020, share the link with friends and acquaintances, this video has already been watched 29,169 times on youtube and it was liked by 955 viewers. Enjoy your viewing!