code for generateDirectory()