Fix bug in WriteToDir