dreamapplehappy / LearnNode

1 stars 0 forks source link

2016-9-23 #1

Open dreamapplehappy opened 8 years ago

dreamapplehappy commented 8 years ago

删除文件(Sync): fs.unlink(path, callback)

fs.unlink('./file', (err) => {
  if(err) {
    throw err;
  }
  console.log('successfully delete ./file');
})
dreamapplehappy commented 8 years ago

删除文件(Async): fs.unlinkSync(path)

let result = fs.unlinkSync('./file');
console.log(result);
console.log('successfully delete ./file');
dreamapplehappy commented 8 years ago

重命名文件(Async): fs.rename(oldPath, newPath, callback)

描述文件信息: fs.stat(path, callback)

fs.rename('./file', './newFile', (err) => {
  if(err) {
    throw err;
  }
  fs.stat('./newFile', (err, stats) => {
    if(err) {
      throw err;
    }
    console.log(`stats: ${JSON.stringify(stats)}`);
  })
})