Separate writing files and directories
separate readDir, avoid fs.stat() in two places