Answers for "delete txt file in python"

36

python os remove file

import os
os.remove("filename.txt")
Posted by: Guest on February-11-2020
2

python delete text in text file

# Delete all text in a text file
f = open("text_file.txt", "r+")
f.truncate(0)
f.close()
Posted by: Guest on April-30-2021
0

Deleting a file using python

import os

# os.remove("text.txt")
# print("File deleted")


for file in os.listdir("fileDirectory"):
    os.remove("fileDirectory"+file)
    print(file, "deleted")
Posted by: Guest on July-16-2021

Python Answers by Framework

Browse Popular Code Answers by Language