Script to flatten directories