Hi everyone. Welcome back to another session on python. If you are new here, please do checkout our previous articles on python and other programming languages. Also subscribe to our YouTube channel for the video tutorials. In this tutorial, we are going to learn how to do the following in python Deleting files in python Checking if files still exist Deleting folders in python Deleting files in python To delete a file in python, we can use the remove() which is called from the os module . This remove() method takes only one arguments. syntax os.remove(file_name) Let’s demonstrate with an example import os # Delete file2.txt os.remove(“file2.txt”) After you must have deleted a file and you want to confirm if the file has been deleted or you might to check if the file still exist before deleting. Here is an example to check if a file has been deleted or still exist import os if os.path.exists("file2.txt"): os.remove("file2.txt") else: print("The file does n...
The latest technical tips and news from the workdiary team