SoFunction
Updated on 2025-03-02

nodejs recursively copy and read all files and directories in the directory

First, let me introduce to you all the files and directories in the nodejs recursive copy directory. The specific code is as follows:

var fs=require('fs');
var copy=function(src,dst){
  let paths = (src); //Read the current directory synchronously  (function(path){
    var _src=src+'/'+path;
    var _dst=dst+'/'+path;
    (_src,function(err,stats){ //stats This object contains file properties      if(err)throw err;
      if(()){ //If it is a file, copy it        let readable=(_src);//Create a read stream        let writable=(_dst);//Create a write stream        (writable);
      }else if(()){ //Yes directory        checkDirectory(_src,_dst,copy);
      }
    });
  });
}
var checkDirectory=function(src,dst,callback){
  (dst, .F_OK, (err) => {
    if(err){
      (dst);
      callback(src,dst);
    }else{
      callback(src,dst);
    }
   });
};
const  SOURCES_DIRECTORY = 'd:commonPrefab'; // Source directorycheckDirectory(SOURCES_DIRECTORY,__dirname,copy);

ps: Let's take a look at all files in the Nodejs recursive reading directory

Recursively read all files in the current directory.

var fs = require('fs');
var path = require('path');
var exec = require('child_process').exec;
function readFileList(dir, filesList = []) {
  const files = (dir);
  (files);
  ((item, index) => {
    var fullPath = (dir, item);
    const stat = (fullPath);
    if (()) {   
      readFileList((dir, item), filesList); //Recursively read the file    } else {        
      (fullPath);           
    }    
  });
  return filesList;
}
var filesList = [];
readFileList(__dirname,filesList);
(filesList);

Summarize

The above is the editor’s introduction to nodejs recursively copying and reading all files and directories in the directory. I hope it will be helpful to everyone. If you have any questions, please leave me a message and the editor will reply to everyone in time. Thank you very much for your support for my website!
If you think this article is helpful to you, please reprint it. Please indicate the source, thank you!