Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python delete file

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
Comment

how to delete file in python

import os
os.remove("ChangedFile.csv")
print("File Removed!")
Comment

deleting a file in python

import os
os.remove('file_path')
Comment

python delete file

import os
os.remove("/tmp/<file_name>.txt")
Comment

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")
Comment

Delete file via Python

#!/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)
Comment

PREVIOUS NEXT
Code Example
Python :: python get script name 
Python :: how to make pyautogui faster 
Python :: check the os in python 
Python :: python clear console 
Python :: how to install pyaudio in python 
Python :: python console pause 
Python :: sleep 5 seconds py 
Python :: selenium python find all links 
Python :: pandas read tab separated file 
Python :: get stats from array python 
Python :: Pandas: How to Drop Rows that Contain a Specific String 
Python :: sort tuple by first element python 
Python :: python for file in dir 
Python :: current datetime pandas 
Python :: incognito in selenium 
Python :: python save figure 
Python :: how to center plotly plot title 
Python :: how to get image in jupyter notebook 
Python :: python apply a function to a list inplace 
Python :: python read xlsb pandas 
Python :: python reimport module after change 
Python :: dataframe to csv python 
Python :: read .dat python 
Python :: how to delete every row in excel using openpyxl 
Python :: python download image from url 
Python :: how to identify GPU with pytorch script 
Python :: python3 install google 
Python :: python rename file 
Python :: numpy to csv 
Python :: python pip install jinja 
ADD CONTENT
Topic
Content
Source link
Name
3+4 =