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 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 :: loop through list backwards python 
Python :: rgb to grayscale python opencv 
Python :: update numpy in python 
Python :: ipykernel pip 
Python :: select rows which have nan values python 
Python :: python read xlsb pandas 
Python :: export image python 
Python :: object to int64 pandas 
Python :: distance between point python 
Python :: convert column to datetime format python 
Python :: how to find ip address of website using python 
Python :: unzip file python 
Python :: split string into array every n characters python 
Python :: python os make empty file 
Python :: timeout exception in selenium python 
Python :: python how to generate random number in a range 
Python :: how to strip quotation marks in python 
Python :: python read file line by line 
Python :: python sleep 5 seconds 
Python :: reverse row order pandas 
Python :: how to calculate rmse in linear regression python 
Python :: pandas add suffix to column names 
Python :: python youtube downloader mp3 
Python :: django user form 
Python :: permanent redirect django 
Python :: numpy fill na with 0 
Python :: install easygui 
Python :: correlation between lists python 
Python :: flask boiler plate 
Python :: check if image is empty opencv python 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =