Implemented function to scan directories