optimised file and directory pattern matching a bit