use dir to write file