Copy folder recursively in Node.js

前端 未结 25 1964
隐瞒了意图╮
隐瞒了意图╮ 2020-12-04 07:44

Is there an easier way to copy a folder and all its content without manually doing a sequence of fs.readir, fs.readfile, fs.writefile

25条回答
  •  Happy的楠姐
    2020-12-04 08:18

    I know so many answers are already here, but no one answered it in a simple way.

    Regarding fs-exra official documentation, you can do it very easy.

    const fs = require('fs-extra')
    
    // Copy file
    fs.copySync('/tmp/myfile', '/tmp/mynewfile')
    
    // Copy directory, even if it has subdirectories or files
    fs.copySync('/tmp/mydir', '/tmp/mynewdir')
    
    

提交回复
热议问题