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

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

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 :: create a role with discord.py 
Python :: horizontal bar plot python 
Python :: webbrowser.google.open python 
Python :: dice rolling simulator python 
Python :: python hello world web application 
Python :: discord.py send messages 
Python :: python run system command 
Python :: python zip extract directory 
Python :: errno 13 permission denied python 
Python :: sort df by column 
Python :: python rsa 
Python :: install from github 
Python :: replace number with string python 
Python :: pandas add two string columns 
Python :: python os remove extension 
Python :: Write a python program to find the most frequent word in text file 
Python :: python convert list of strings to list of integers 
Python :: string startswith python 
Python :: tuple slicing in python 
Python :: python how to get current line number 
Python :: how to import flask restful using pip 
Python :: convert a number column into datetime pandas 
Python :: python numba 
Python :: python string replace index 
Python :: pandas dataframe column names 
Python :: delete the content from the entry form in tkinter python 
Python :: python - remove duplicate items from the list 
Python :: how to load keras model from json 
Python :: python how to get the screen size 
Python :: python currency symbol 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =