对路径没有做验证
复制文件
var fs = require('fs');
var path = require('path');
var fileName = "coverflow-3.0.1.zip";
var sourceFile = path.join(__dirname, fileName);
var destPath = path.join(__dirname, "dest", fileName);
var readStream = fs.createReadStream(sourceFile);
var writeStream = fs.createWriteStream(destPath);
readStream.pipe(writeStream);
console.log("移动完成")
移动文件可以用 fs.rename()
来实现
如果目标文件夹下有同名文件,则会被覆盖。
var fs = require('fs');
var path = require('path');
var fileName = "coverflow-3.0.1.zip";
var sourceFile = path.join(__dirname, fileName);
var destPath = path.join(__dirname, "dest", fileName);
fs.rename(sourceFile, destPath, function (err) {
if (err) throw err;
fs.stat(destPath, function (err, stats) {
if (err) throw err;
console.log('stats: ' + JSON.stringify(stats));
});
});