Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Delete all content in folder with Python [closed]

Tags:

python

Following this answer, I'm trying to delete the contents of a folder with this code

import os
import glob

files = glob.glob('/YOUR/PATH/*')
for f in files:
    os.remove(f)

But python returns an Attribution Error "'str' object has no attribute 'remove'". What am I'm doing wrong?

like image 616
Ricardo Dahis Avatar asked Jan 25 '16 00:01

Ricardo Dahis


1 Answers

For deleting an entire directory, use shutil.rmtree('/your/path')

Read more from Python docs

Check out a similar question that has already been answered

like image 196
Bob Ezuba Avatar answered Oct 29 '22 04:10

Bob Ezuba