-
Notifications
You must be signed in to change notification settings - Fork 0
/
globtest.js
41 lines (38 loc) · 1.14 KB
/
globtest.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
const fs = require("fs")
const glob = require("glob")
var getDirectories = function (src) {
return new Promise((resolve, reject) => {
glob(src + '/**/*', (err, files) => {
if (err) reject(err)
for (let x = 0; x < files.length; x++) {
if (fs.lstatSync(files[x]).isDirectory()) {
files[x] += "?"
}
files[x] = files[x].substring(src.length + 1)
}
resolve(files)
});
})
};
// getDirectories('data').catch(err => {})
// .then(res => {
// console.log(res)
// })
async function v(directory) {
return new Promise((resolve, reject) => {
glob(directory + '/**/*', (err, files) => {
console.log(files)
if (err) reject(err)
for (let x = 0; x < files.length; x++) {
if (fs.lstatSync(files[x]).isDirectory()) {
files[x] += "?"
}
files[x] = files[x].substring(directory.length + 1)
}
resolve(files)
});
})
}
v("data").then(res => console.log(res)).catch(err => {
throw err
})