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

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 :: python sort two key 
Python :: Import A Model 
Python :: how to add mouse button in pygame 
Python :: axes color python 
Python :: discord py bot example 
Python :: pandas index from 1 
Python :: python find in largest 3 numbers in an array 
Python :: how to delete json object using python? 
Python :: how to load wav file with python 
Python :: python google chrome 
Python :: python opencv draw rectangle with mouse 
Python :: Permission denied in terminal for running python files 
Python :: python file parent 
Python :: python remove spaces 
Python :: write list to file python 
Python :: permutations of a set 
Python :: python cheat sheet 
Python :: python fillna with mode 
Python :: neuronal network exemple python 
Python :: concatenate 2 array numpy 
Python :: sort a string in python 
Python :: python reserved keywords 
Python :: spacy config 
Python :: rotate image in pygame 
Python :: python add up values in list 
Python :: python find index by value 
Python :: delete columns pandas 
Python :: python classes 
Python :: standardise columns python 
Python :: dataframe create 
ADD CONTENT
Topic
Content
Source link
Name
6+1 =