首先fs-extra在您的项目中安装模块,npm install fs-extra然后按照以下步骤操作:
导入以下内容
var fs = require('fs');
var fs_Extra = require('fs-extra');
var path = require('path');
Run Code Online (Sandbox Code Playgroud)
// 在这里声明你的路径
var sourceDir = path.join(__dirname, "../working");
var destinationDir = path.join(__dirname, "../worked")
Run Code Online (Sandbox Code Playgroud)
// 如果文件夹不存在则创建它
if (!fs.existsSync(destinationDir)){
fs.mkdirSync(destinationDir, { recursive: true });
}
Run Code Online (Sandbox Code Playgroud)
// 复制文件夹内容
fs_Extra.copy(sourceDir, destinationDir, function(error) {
if (error) {
throw error;
} else {
console.log("success!");
}
});
Run Code Online (Sandbox Code Playgroud)
注意:源文件夹名称和目标文件夹名称不应相同。
| 归档时间: |
|
| 查看次数: |
11802 次 |
| 最近记录: |