refactor directory related codes to util