added mkdirs to write method