generic function for dir walk