1import os
2import shutil
3
4if os.path.exists("demofile.txt"):
5 os.remove("demofile.txt") # one file at a time
6
7os.rmdir("test_directory") # removes empty directory
8shutil.rmtree("test_directory") # removes not empty directory and its content
9
1import os
2filePath = '/home/somedir/Documents/python/logs'
3
4if os.path.exists(filePath):
5 os.remove(filePath)
6else:
7 print("Can not delete the file as it doesn't exists")