Search
 
SCRIPT & CODE EXAMPLE
 

PYTHON

python dlete folder

import shutil

shutil.rmtree('/folder_name')
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 :: unable to locate package python-pip 
Python :: how to check weather my model is on gpu in pytorch 
Python :: python pdf to image 
Python :: pygame.rect parameters 
Python :: how to take array input in python in single line 
Python :: format to 2 or n decimal places python 
Python :: plot to image python 
Python :: python log with timestamp 
Python :: get the torch version 
Python :: save clipboard data win32clipboard python 
Python :: python resize image 
Python :: unzip in python 
Python :: python split string in pairs 
Python :: pandas update with condition 
Python :: show a video cv2 
Python :: pyttsx3 save to file 
Python :: spacy en_core_web_sm error 
Python :: install python on windows subsystem for linux 
Python :: beuatiful soup find a href 
Python :: reverse column order pandas 
Python :: how to get just the filename in python 
Python :: pygame get mouse position 
Python :: youtube dl download mp3 python 
Python :: how to check for a particular word in a text file using python 
Python :: python dictionary sort in descending order 
Python :: open image in numpy 
Python :: python time now other timezone 
Python :: stopwatch in python 
Python :: pandas print first column 
Python :: check if string url python 
ADD CONTENT
Topic
Content
Source link
Name
2+4 =