import os
def del_path(path): if not os.path.exists(path): return if os.path.isfile(path): os.remove(path) print 'delete file %s' % path else: items = os.listdir(path) for f in items: c_path = os.path.join(path, f) if os.path.isdir(c_path): del_path(c_path) else: os.remove(c_path) print 'delete file %s' % c_path os.rmdir(path) print 'delete dir %s' % path
if __name__ == '__main__':
del_path('./111')