-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathls.js
More file actions
executable file
·33 lines (29 loc) · 823 Bytes
/
Copy pathls.js
File metadata and controls
executable file
·33 lines (29 loc) · 823 Bytes
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
#!/usr/bin/env babel-node
require('./helper')
const fs = require('fs').promise
const path = require('path')
const args = require('yargs').argv
async function ls(dir, fileList, fullPath) {
const files = await fs.readdir(dir)
for (const file of files) {
const filePath = dir + file
const stat = await fs.stat(filePath)
if (args['R']) {
if (stat.isDirectory())
fileList = await ls(dir + file + '/', fileList, fullPath + '/' + file)
else
fileList.push(fullPath + '/' + file)
} else if (!stat.isDirectory())
fileList.push(file)
}
return fileList
}
async function main() {
const dir = args._[0] || ''
const filePath = path.join(__dirname, dir)
const fileList = await ls(filePath + '/', [], '')
for (const file of fileList) {
console.log(file)
}
}
main()