Abstracted directory parsing function