-
Notifications
You must be signed in to change notification settings - Fork 1
/
copydir.js
42 lines (36 loc) · 918 Bytes
/
copydir.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const fs = require('fs')
const path = require('path')
function copydir(f, t, c = {}) {
let _f = f, _t = t
if(c.relative) {
let _f = path.resolve(process.cwd(), f)
let _t = path.join(process.cwd(), t)
}
_copydir(_f, _t);
}
function _copydir(f, t) {
try {
fs.accessSync(t);
} catch (e) {
fs.mkdirSync(t);
}
try {
fs.readdirSync(f).forEach(function (p) {
let _f = f + '/' + p;
let _t = t + '/' + p;
try {
let stat = fs.statSync(_f)
if (stat.isFile()) {
fs.writeFileSync(_t, fs.readFileSync(_f));
} else if (stat.isDirectory()) {
_copydir(_f, _t)
}
} catch (e) {
console.log(e)
}
})
} catch (e) {
console.log(e)
}
}
module.exports = copydir