Node moves files to another directory

There is an attribute in

node that can move files directly to another directory, which seems to start with p. I"ve seen it before, but I can"t find that article now!

fs.rename  fs.copyFile

Feb.11,2022

I am tired of handwriting. Use shelljs/shelljs" rel=" nofollow noreferrer "> library (shelljs) directly:

/**
* index.js
* 
*/

// nodejs 
const fs = require('fs')
const files = fs.readdirSync('./')

// 
//  : https://blog.csdn.net/qq_37899792/article/details/105512853
function isDirectory(fileName) {
    const stat = fs.lstatSync(fileName);
    return stat.isDirectory()
}

const shell = require('shelljs');

for (let index = 0; index < files.length; indexPP) {
    const path = files[index];
    if(isDirectory(path) && path !== 'node_modules'){
        shell.cp('-r', path + '/*', './');
        // shell.rm('-r', path);
    }
}

Note that / *' and '/' are different

< hr >

PS: refer to


so it seems to use readableStream.pipe () . It used to be util.pipe ()
see here https://nodejs.org/api/stream.


change the way of thinking, use the linux command mv, ha

Menu