文件夹拷贝
function CopyDirectory(src, dest) {
if (IsFileExist(dest) == false) {
fs.mkdirSync(dest);
}
if (fs.existsSync(src) == false) {
return false;
}
// console.log("src:" + src + ", dest:" + dest);
// 拷贝新的内容进去
var dirs = fs.readdirSync(src);
dirs.forEach(function(item){
var item_path = path.join(src, item);
var temp = fs.statSync(item_path);
if (temp.isFile()) { // 是文件
// console.log("Item Is File:" + item);
fs.copyFileSync(item_path, path.join(dest, item));
} else if (temp.isDirectory()){ // 是目录
// console.log("Item Is Directory:" + item);
CopyDirectory(item_path, path.join(dest, item));
}
});
}
文件夹删除
function DeleteDirectory(dir) {
if (fs.existsSync(dir) == true) {
var files = fs.readdirSync(dir);
files.forEach(function(item){
var item_path = path.join(dir, item);
// console.log(item_path);
if (fs.statSync(item_path).isDirectory()) {
DeleteDirectory(item_path);
}
else {
fs.unlinkSync(item_path);
}
});
fs.rmdirSync(dir);
}
}