要使用NPM(節(jié)點(diǎn)軟件包管理器)安裝Node fs-extra軟件包,請(qǐng)?jiān)诮K端中運(yùn)行以下命令。
node-js-copy-a-foder.js
// 引入fs-extra軟件包 var fs = require("fs-extra"); var source = 'folderA' var destination = 'folderB' // 將源文件夾復(fù)制到目標(biāo) fs.copy(source, destination, function (err) { if (err){ console.log('An error occured while copying the folder.') return console.error(err) } console.log('Copy completed!') });
在帶有節(jié)點(diǎn)的終端命令中運(yùn)行以上腳本
Node.js腳本終端輸出
arjun@arjun-VPCEH26EN:~/workspace/nodejs$ node node-js-copy-a-foder.js Copy completed!
在這種Node.js的教程-節(jié)點(diǎn)FS - Node.js的拷貝一個(gè)文件夾,我們已經(jīng)學(xué)會(huì)了安裝節(jié)點(diǎn)FS-額外的包和文件夾或目錄復(fù)制(包含文件和一些文件夾),使用到其他位置 節(jié)點(diǎn)FS-EXTRA借助示例腳本進(jìn)行打包。