Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

delete files inside folder python

import os
import glob

files = glob.glob('/YOUR/PATH/*')
for f in files:
    os.remove(f)
Comment

python delete folder and contents

import shutil
shutil.rmtree("dir-you-want-to-remove")
Comment

python how to delete a directory with files in it

import shutil

dir_path = '/tmp/img'

try:
    shutil.rmtree(dir_path)
except OSError as e:
    print("Error: %s : %s" % (dir_path, e.strerror))
Comment

How to delete a file or folder in Python?

os.remove() removes a file.

os.rmdir() removes an empty directory.

shutil.rmtree() deletes a directory and all its contents.
Comment

PREVIOUS NEXT
Code Example
Python :: check if user log in flask 
Python :: python randomize list 
Python :: python float to fraction 
Python :: how to open file explorer in python 
Python :: python cv2 resize keep aspect ratio 
Python :: python generate uid 
Python :: wxpython change window size 
Python :: regex email python 
Python :: how to remove the very last character of a text file in python 
Python :: python get domain from url 
Python :: log transform pandas dataframe 
Python :: python get num classes from label encoder 
Python :: python how often character ins tring 
Python :: get from time secs and nsecs 
Python :: How to save XLSX file to ir_attachment odoo 
Python :: draw pixel by pixel python 
Python :: ignore error open file python 
Python :: virtual env in mac 
Python :: python get words between two words 
Python :: is there a replacement for ternary operator in python 
Python :: import math print(math.log(1024,2)) 
Python :: write a program to check whether a character is vowel or consonant in python 
Python :: pyplot legend outside figure 
Python :: matplotlib 3.0.3 wheel file 
Python :: rotation points space python 
Python :: wap to draw the shape of hexagonn in python 
Python :: python counter get most common 
Python :: np.sort descending 
Python :: TypeError: Unicode-objects must be encoded before hashing 
Python :: how to python hack 2021 course 
ADD CONTENT
Topic
Content
Source link
Name
9+6 =