extract file and dir matching in seperate method