Python delete a file 🗑️

preview_player
Показать описание
Python delete file tutorial example explained

#python #delete #file

import os
import shutil

try:
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")

Рекомендации по теме
Комментарии
Автор

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")

BroCodez
Автор

Hey bro. thanks for the video, nice programming tutorial for python as usual.

lw
Автор

Thanks bro...One day for sure I will be a successful coder only because of you bro!
Thank for making videos..
God bless you❤

mgkwzpp
Автор

I've been looking for a way to remove an imported file from a program without permanently deleting it, once it has served it's purpose. Is this possible?

soundtracksbymax
Автор

A smooth and beautiful explanation, thank you, but I was wondering if the shutil library works on Android, and also how can I delete the device’s storage in Android completely?

omarmohmad
Автор

I just have one question: where do the deleted files go?

laurabassino
Автор

Unused import statement 'import os'
i get this error
when i copy your text
i wont get it why?

NAMEETROXX
Автор

how do i grant permission to remove a file in windows?

andresalcaino
Автор

instructions unclear ended up deleting my jetbrains program files

alisajjad
Автор

What you try to delete something expecting an error and actually deleting it and now have to write it again 😐

elonhusk
Автор

And with this video we remove the mine series of files

joelpaquete
Автор

I accidentally deleted one of the windows folder…lol

flammabletfm