Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python dlete folder

import shutil

shutil.rmtree('/folder_name')
Comment

delete contents of directory 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

delete folders using python

import shutil
shutil.rmtree(r'Path where the folder with its files is storedFolder name')
Comment

Python Removing Directory or File

>>> os.listdir()
['new_one', 'old.txt']

>>> os.remove('old.txt')
>>> os.listdir()
['new_one']

>>> os.rmdir('new_one')
>>> os.listdir()
[]
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

Python delete directory contents

import os, shutil
folder = '/path/to/folder'
for filename in os.listdir(folder):
    file_path = os.path.join(folder, filename)
    try:
        if os.path.isfile(file_path) or os.path.islink(file_path):
            os.unlink(file_path)
        elif os.path.isdir(file_path):
            shutil.rmtree(file_path)
    except Exception as e:
        print('Failed to delete %s. Reason: %s' % (file_path, e))
Comment

PREVIOUS NEXT
Code Example
Python :: adding one element in dictionary python 
Python :: while activating env show error of unautorize access in vscode 
Python :: python euclidean distance 
Python :: python dictionary multiple same keys 
Python :: remove na python 
Python :: encrypt password with sha512 + python 
Python :: estimate time to run a chunk of code in python 
Python :: dictionary get all keys 
Python :: reversed function python 
Python :: get the name of all files in a computer in python 
Python :: how to check encoding of csv 
Python :: cv2 read rgb image 
Python :: how to get the max of a list in python 
Python :: gdscript tween 
Python :: access class variable from another class python 
Python :: try except raise 
Python :: Hungry Chef codechef solution 
Python :: how to import and use keyboard with pygame 
Python :: Flask command db migrate 
Python :: importing python module from different directory 
Python :: maximum element in dataframe row 
Python :: import flask session 
Python :: Python write value in next row of existing .text file 
Python :: python ord() 
Python :: np.tanh 
Python :: what does % do in python 
Python :: python constant 
Python :: how to make a numpy array of certain values 
Python :: scrapy shell 
Python :: how to make an array in python 
ADD CONTENT
Topic
Content
Source link
Name
4+4 =