Answers for "python delete file contents"

10

python delete contents of file

f = open('file.txt', 'r+')
f.truncate(0)
Posted by: Guest on February-22-2020
3

python delete contents of file

open('file.txt', 'w').close()
Posted by: Guest on February-22-2020
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

Code answers related to "python delete file contents"

Python Answers by Framework

Browse Popular Code Answers by Language