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

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1b3ab93-2c23f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1b3ab93-2c23f.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?