expand general-purpose implementation to cover multiple directories