Extract export env dir into a funciton