How would I empty my linux trash from python?
Would I just do a simple os.remove? Or is there an easier way? I am also working on deleting all files within a directory, for multiple directories.
I have found this:
#!/usr/bin/env python
import os
def nukedir(dir):
if dir[-1] == os.sep: dir = dir[:-1]
files = os.listdir(dir)
for file in files:
if file == '.' or file == '..': continue
path = dir + os.sep + file
if os.path.isdir(path):
nukedir(path)
else:
os.unlink(path)
os.rmdir(dir)
nukedir("/home/mb/test");