om: refactor directory iteration code into utility