untio-hua-delplus

1.0.0 • Public • Published

#fs算法

##fs文件夹拷贝

function copydir(dir, newdir) {
    !fs.existsSync(newdir) && fs.mkdirSync(newdir);
    fs.readdirSync(dir).forEach(item => {
        let dirname = dir + '/' + item;
        let newdirName = newdir + '/' + item;
        if (fs.statSync(dirname).isFile()) {
            fs.copyFileSync(dirname, newdirName);
        } else {
            copydir(dirname, newdirName);
        }
    })
}

##fs文件删除代码

function del(fileSrc) {
    fs.readdirSync(fileSrc).forEach(item => {
        item = fileSrc + '/' + item;
        console.log(item);
        if (fs.statSync(item).isFile()) {
            fs.unlinkSync(item);
        } else {
            del(item);
        }
    })
    fs.rmdirSync(fileSrc);
}

Readme

Keywords

none

Package Sidebar

Install

npm i untio-hua-delplus

Weekly Downloads

0

Version

1.0.0

License

ISC

Unpacked Size

2.26 kB

Total Files

4

Last publish

Collaborators

  • hxb3035218676