javascript 递归File Walker

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了javascript 递归File Walker相关的知识,希望对你有一定的参考价值。

'use strict';
// node v10.0.0
const fs = require('fs');
const path = require('path');
const paths = require('../../paths');

/**
 * Recursively walk dir to retrieve all files
 * @param  {string}		Directory where our files are located
 * @return {[string]}
 */
const recursiveFileWalker = (dir) => {
	let results = [];
  // When fs.readdir() or fs.readdirSync() is called with the withFileTypes option set to true,
  // the resulting array is filled with fs.Dirent objects, rather than strings or Buffers.
  // https://nodejs.org/api/fs.html#fs_class_fs_dirent
  // Added as of node v10.0.0
	fs.readdirSync(dir, { withFileTypes: true }).forEach((file) => {
		if (file.isDirectory()) {
			results = [
				...recursiveFileWalker(path.join(dir, file.name)),
				...results,
			];
		}
		else {
			results.push(path.join(dir, file.name));
		}
	});
	return results;
};

module.exports = recursiveFileWalker;

以上是关于javascript 递归File Walker的主要内容,如果未能解决你的问题,请参考以下文章

wordpress menu-walker 中的 ACF 对象

text Wp walker菜单

php 默认Walker主菜单

php Bootstrap 4 Nav Walker

php 自定义WP Nav Walker

php 扩展Walker_Nav_Menu