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
2if os.path.exists("demofile.txt"):
3 os.remove("demofile.txt")
4else:
5 print("The file does not exist")
1import os
2
3# os.remove("text.txt")
4# print("File deleted")
5
6
7for file in os.listdir("fileDirectory"):
8 os.remove("fileDirectory"+file)
9 print(file, "deleted")
10