if tmp contains directories, cleanup task fails. Add management for directories too

Fix when tmp dir contains directories