function which searches for files with a pattern