Remove all files in a directory

os.remove() does not work on a directory, and os.rmdir() will only work on an empty directory. And Python won’t automatically expand “/home/me/test/*” like some shells do.

You can use shutil.rmtree() on the directory to do this, however.

import shutil
shutil.rmtree('/home/me/test') 

be careful as it removes the files and the sub-directories as well.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)