[add] ls function can recur list child folder with second para set to be true.
parent
b31001bd93
commit
891a6cca41
|
@ -1,3 +1,7 @@
|
|||
1.0.1 / 2017-04-24
|
||||
* [add] ls function can recur list child folder with second para set to be true.
|
||||
|
||||
|
||||
1.0.0 / 2017-02-26
|
||||
==================
|
||||
|
||||
|
|
|
@ -19,10 +19,12 @@
|
|||
|
||||
|
||||
|
||||
### ls(path)
|
||||
### ls(path, child)
|
||||
- path `<String>`
|
||||
- child `<Boolean>`
|
||||
|
||||
> List all files and folders of the path given exclude '.' and '..'. I t return an array.
|
||||
> If para `child` is set to be ture, it will recur list all files of child dir.
|
||||
|
||||
|
||||
### echo(data, file[, append][, encode])
|
||||
|
|
21
index.js
21
index.js
|
@ -32,12 +32,27 @@ class Iofs {
|
|||
|
||||
/**
|
||||
* [ls 读取整个目录(不遍历子目录)]
|
||||
* @param {string} file [目标路径]
|
||||
* @param {string} dir [目标路径]
|
||||
* @param {boolean} child [是否遍历子目录]
|
||||
* @return {array} [返回目标目录所有文件名和子目录名, 不包括'.'和'..']
|
||||
*/
|
||||
ls(file){
|
||||
ls(dir, child){
|
||||
try{
|
||||
return fs.readdirSync(file)
|
||||
let list = fs.readdirSync(dir)
|
||||
|
||||
if(!child)
|
||||
return list
|
||||
|
||||
let tmp = Array.from(list)
|
||||
tmp.forEach(it => {
|
||||
let childdir = path.join(dir, it)
|
||||
if(this.isdir(childdir)){
|
||||
list = Array.prototype.concat.apply(list, this.ls(childdir, true).map(sub => {
|
||||
return path.join(it, sub)
|
||||
}))
|
||||
}
|
||||
})
|
||||
return list
|
||||
}catch(err){
|
||||
console.error(err)
|
||||
return null
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "iofs",
|
||||
"version": "1.0.0",
|
||||
"version": "1.0.1",
|
||||
"description": "Base on native fs module, for easy using.",
|
||||
"main": "index.js",
|
||||
"repository": {
|
||||
|
|
Loading…
Reference in New Issue