Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

if file exists delete python

import os
filePath = '/home/somedir/Documents/python/logs'

if os.path.exists(filePath):
    os.remove(filePath)
else:
    print("Can not delete the file as it doesn't exists")
Comment

if file exist in folder then delete in python

import os
os.remove(fn) if os.path.exists(fn) else None  #here fn - filename or filepath
Comment

PREVIOUS NEXT
Code Example
Python :: number table python 
Python :: angle names matplotlib 
Python :: get yesterday date python 
Python :: selenium Keys enter python 
Python :: matplotlib dark mode 
Python :: open firefox python 
Python :: sort dataframe by column 
Python :: get external ip python 
Python :: how to open any program on python 
Python :: remocve pyc files 
Python :: delete column pandas dataframe 
Python :: python print time 
Python :: python check is os is windows 
Python :: how to get the url of the current page in selenium python 
Python :: resize imshow opencv python 
Python :: tensorboard in colab 
Python :: how to automatically copy an output to clipboard in python 
Python :: how to feature selection in python 
Python :: how to print hostname in python 
Python :: sort by index 2d array python 
Python :: python loop through all folders and subfolders 
Python :: change specific column name pandas 
Python :: python iterate list reverse 
Python :: how to check if python has been added to path 
Python :: pip.exe The system cannot find the file specified 
Python :: how to make downloadable file in flask 
Python :: convert string list to float 
Python :: how to delete last N columns of dataframe 
Python :: pdb set trace 
Python :: change column order dataframe python 
ADD CONTENT
Topic
Content
Source link
Name
4+2 =