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 selenium go back 
::  
Python :: python get location of script 
:: python get utc time 
Python ::  
::  
Python ::  
::  
::  
::  
Python ::  
::  
::  
Python ::  
::  
::  
::  
::  
:: export image python 
::  
::  
Python ::  
::  
::  
::  
Python :: Python function remove all whitespace from all character columns in dataframe 
:: python write to json with indent 
::  
::  
:: adding whitenoise to middleware in django 
ADD CONTENT
Topic
Content
Source link
Name
3+5 =