fs模块基础

2019-11-18  本文已影响0人  Wrestle_Mania

stat: 统计

fs.stat("htmla", (err, stat) => {
  if(err) throw err;
  console.log(stat.isDirectory());
  console.log(stat.isFile());
});
fs.mkdir("html", err => {
  if(err) throw err;
  console.log("创建目录成功");
});
fs.writeFile("html/demo.txt", "JonSnow", err => {
  if (err) throw err;
  console.log("文件写入成功");
});
fs.appendFile("html/demo.txt", "Cercei", err => {
  if (err) throw err;
  console.log("数据已追加到文件");
});

fs.readFile("html/demo.txt", (err, data) => {
  if (err) throw err;
  console.log(data.toString());
});
fs.readdir("demo", (err, files) => {
  if (err) throw err;
  console.log(files);
});
fs.rename("demo/index.html", "demo/aaa.html", err => {
  if (err) throw err;
  console.log("文件名修改成功");
});
fs.rename("demo/index.html", "demo/html/index.html", err => {
  if (err) throw err;
  console.log("文件剪切成功");
});
fs.rmdir("demo/html/demo", err => {
  if (err) throw err;
  console.log("目录删除成功");
});
fs.unlink("demo/html/demo.txt", err => {
  if (err) throw err;
  console.log("文件删除成功");
});
上一篇 下一篇

猜你喜欢

热点阅读