Factor the directory chooser into its own function.