1.0.1 • Published 9 months ago

@xingqitian/each-dir-tree v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

遍历目录树

遍历指定路径的目录树

示例

eachDirTree(callback, dirPath, ignores)

  • callback <Function> 必须的: 处理每个文件/文件夹的回调函数。
  • dirPath <string> 必须的: 文件夹的绝对路径。
  • ignores <string[] | undefined> 可选的: 忽略的文件/文件夹列表。

遍历指定的文件夹, 并调用 callback 函数

eachDirTree((fileItem) => {
  // fileItem =>> { 
  //    path: string; // 文件/文件夹的绝对路径
  //    isDirectory: boolean; // 是否为文件夹
  // }
}, dirPath, ['node_modules'])

dirFileList(dirPath, ignores)

  • dirPath <string> 必须的: 文件夹的绝对路径。
  • ignores <string[] | undefined> 可选的: 忽略的文件/文件夹列表。

获取指定文件夹下所有的文件列表, 返回一个包含所有文件绝对地址的数组

const fileList = dirFileList(dirPath, ['node_modules'])
// fileList =>> string[]

dirTree(dirPath, ignores)

  • dirPath <string> 必须的: 文件夹的绝对路径。
  • ignores <string[] | undefined> 可选的: 忽略的文件/文件夹列表。

获取指定文件夹下的文件树, 返回一个树结构, 包含 pathisDirectorychildren 三个字段

const dirTree = dirFileList(dirPath, ['node_modules'])
// dirTree =>> Array<{
//  path: string; // 文件/文件夹的绝对路径
//  isDirectory: boolean; // 是否为文件夹
//  children: Array<Object>; // 子集
// }>
1.0.1

9 months ago

1.0.0

9 months ago