scan directory function