import os
import shutil
if os.path.exists("demofile.txt"):
os.remove("demofile.txt") # one file at a time
os.rmdir("test_directory") # removes empty directory
shutil.rmtree("test_directory") # removes not empty directory and its content
import os
os.remove("ChangedFile.csv")
print("File Removed!")
import os
os.remove('file_path')
import os
os.remove("/tmp/<file_name>.txt")
import os
# os.remove("text.txt")
# print("File deleted")
for file in os.listdir("fileDirectory"):
os.remove("fileDirectory"+file)
print(file, "deleted")
#!/usr/bin/python
import os
myfile="/tmp/foo.txt"
## If file exists, delete it ##
if os.path.isfile(myfile):
os.remove(myfile)
else: ## Show an error ##
print("Error: %s file not found" % myfile)