SOURCE

function fs() {}
function path() {}

// 广度优先遍历文件列表
function withdReadFile(dirPath) {
  if (!dirPath) return []

  // 队列
  const queue = []
  const fileList = []

  queue.push(dirPath)

  while(queue.length) {
    // 出队 先进先出
    const currentDirPath = queue.shift()

    // 定义文件对象
    const fileObj = {}
    fileObj.name = currentDirPath

    // 文件状态
    const satas = fs.statSync(currentDirPath)

    // 如果是文件夹
    if (satas.isDirectory()) {
      fileObj.type = 'dir'
      fileList.push(fileObj)

      const children = fs.readdirSync(currentDirPath)

      // 入队
      for (let i = 0, len = children.length; i < len; i++) {
        const childPath = path.join(currentDirPath, children[i])
        queue.push(childPath)
      }

    } else {
      fileObj.type = path.extname(currentDirPath).substring(1)
      fileList.push(fileObj)
    }
  }

  return fileList
}
console 命令行工具 X clear

                    
>
console