Improve file.directory for clean=True

Handle exclude_pat when running with test=True and add
some tests to verify correct behavior.
Merge pull request #5479 from cfra/directory-clean

Improve file.directory for clean=True