node-find-folder
Walk a directory tree in node.js. Use just the name to find the folder(s) you want, rather than through given path(s).
Last updated 3 years ago by itonyyo .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install node-find-folder 
SYNC missed versions from official npm registry.

find-folder

Gitter codebeat badge Build status Build Status Project Dependencies Project devDependencies Issues Closed In... Pull Request Closed In... MIT LICENSE NPM · downloads, rank and stars

Primer

Walk a directory tree in node.js. Use just the name to find the folder(s) you want, rather than through given path(s) - To search the targeted directory(s) you want in the whole project,return array type result. Then, you can do anything you want with the result! For batch operations which according to the directory(s).

It uses the glob library to do some matching work.

Primer

Walk a directory tree in node.js. Use just the name to find the folder(s), rather than through given path(s) - To search the targeted directory(s) you want in the whole project,return array type result. Then, you can do anything you want with the result! For batch operations which according to the directory(s).

It uses the glob library to do some matching work.

Usage

First, you should know the Folder structure for demo below.

Install

how to install

You can use --save-dev param after the command above to save node-find-folder to package.json

Code details,

var ff, ff_result;

ff = require('node-find-folder');

/*
  if '1' is under 'dev/image/ui_icon_social_64px',
  and '1' is folder,
  then output will be ['dev/image/ui_icon_social_64px/1'].
*/
ff_result = new ff('1');

Exist the same folder under some directories! But I just need one of them! How should I do?

A: You can do like this:

/*
  output: ['dev/image/ui_icon_social_32px/grey']
  not: [
    'dev/image/ui_icon_keyamoon_32px/grey',
    'dev/image/ui_icon_social_32px/grey'
    ]
*/
ff_result = new ff('grey', {
  ignore: ['dev/image/ui_icon_keyamoon_32px/grey']
});

I don't want to traverse folders like .git, node_modules and dest which are in the root of project! Maybe more... How should I do?

A: By default, this module will ignore .git, node_modules two folders. So you can just do like this:

/*
  the ".git", "node_modules" and "dest" folders
  will not be traversed in this way.
*/
ff_result = new ff('grey', {
  nottraversal: ['dest']
});

Want more features? Let's improve this module togethor!

Code without node-find-folder,

...

var order, cln_prefix;

// the name of folder
order      = [
  'ui_icon_keyamoon_16px',
  'ui_icon_keyamoon_32px',
  'ui_icon_social_32px'
];
cln_prefix = 'clean-';

order.forEach((the) => {
	gulp.task(cln_prefix + the, () => {
		fs.readdir(process.cwd(), (err, files) => {
			let deal = (_item, _index, _array) => {
				if (isDir(_item)) {
					if (_item === the) {
						del(_item + '/*');
					}
				}
			};
			files.forEach(deal);
		});
	});
});

gulp.task('clean', order.map(function (the) {
	return cln_prefix + the;
}));

...

The code above is too much... and not flexible...

Code with node-find-folder,

...

var ff, order, cln_prefix;

ff = require('node-find-folder');

// the name of folder
order      = [
  'ui_icon_keyamoon_16px',
  'ui_icon_keyamoon_32px',
  'ui_icon_social_32px'
];
cln_prefix = 'clean-';

order.forEach((the) => {
	gulp.task(cln_prefix + the, () => {
		let ff_result = new ff(the);
		ff_result.forEach((_item, _index, _array) => {
			del(_item + '/*');
		});
	});
});

gulp.task('clean', order.map((the) => {
	return cln_prefix + the;
}));

...

Code is simple, flexible and well-understood! The most important thing is that you can focus on your operation.

API

getFolders(folderName, [options])

Return array type data which contain the path(s) of matched folder(s).

Options

  • nottraversal, Array type; default value is ['.git', 'node_modules']; for top-level directories which need to be ignored.

  • ignore, Array type; default value is []; for specific path to folder(s) which need to be ignored.

Helping node-find-folder

What's node-find-folder working on next?

You can check the plan of development in my related Trello board! I use Trello to manage the plan of this project. And we can discuss a lot through the related board! Of course we can use Gitter to discuss, too! You can choose your favorite kind of communication form!

My requirement is not met!

A person's strength is limited, I will ignore something... Or, I just did not get the idea what you think... If you'd like to help to improve the project, whelcome you to present your ideas on Gitter or Trello. I will be very gratefull!

I found a bug!

If you found a repeatable bug, and tips from Usage section didn't help, then be sure to search existing issues first. If there's no content is similar with the problem you found, welcome you to create a new issue you found!

I want to help with the code!

Awesome! I use Github to managed code. So there are lots of ways you can help. First read CONTRIBUTING.md, then learn be social with Github and how to pull the repo on node-find-folder.

Contact info

LICENSE

See also LICENSE .

Current Tags

  • 0.1.32                                ...           latest (3 years ago)

23 Versions

  • 0.1.32                                ...           3 years ago
  • 0.1.31                                ...           3 years ago
  • 0.1.30                                ...           3 years ago
  • 0.1.29                                ...           3 years ago
  • 0.1.28                                ...           3 years ago
  • 0.1.27                                ...           4 years ago
  • 0.1.26                                ...           4 years ago
  • 0.1.25                                ...           4 years ago
  • 0.1.21                                ...           5 years ago
  • 0.1.14                                ...           5 years ago
  • 0.1.13                                ...           5 years ago
  • 0.1.12                                ...           5 years ago
  • 0.1.11                                ...           5 years ago
  • 0.1.10                                ...           5 years ago
  • 0.1.9                                ...           5 years ago
  • 0.1.8                                ...           6 years ago
  • 0.1.7                                ...           6 years ago
  • 0.1.6                                ...           6 years ago
  • 0.1.5                                ...           6 years ago
  • 0.1.3                                ...           6 years ago
  • 0.1.2                                ...           6 years ago
  • 0.1.1                                ...           6 years ago
  • 0.1.0                                ...           6 years ago

Copyright 2014 - 2016 © taobao.org |