1.0.2 • Published 4 years ago

fn-copy-17 v1.0.2

Weekly downloads
1
License
ISC
Repository
-
Last release
4 years ago

这是一个复制函数!!!

const fs = require("fs");

const copyDir = (source, target) => {
    // 判断源文件是否存在
    if (!fs.existsSync(source)) {
        throw new Error("源文件不存在!!!");
        return;
    }
    // 判断目标文件是否存在
    if (fs.existsSync(target)) {
        throw Error("目标文件存在!!!");
        return;
    }
    // 创建目标文件
    fs.mkdirSync(target);
    fs.readdirSync(source).forEach(item => {
        let sourceMidd = source + '/' + item,
            targetMidd = target + '/' + item;
        if (fs.statSync(sourceMidd).isFile()) {
            fs.copyFileSync(sourceMidd, targetMidd);
        } else {
            copyDir(sourceMidd, targetMidd);
        }
    });
}
module.exports = { copyDir };


const res = fs.statSync('../1.txt');
console.log(res);
1.0.2

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago