Serialize and deserialize directory.