web 3d图形渲染器
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

69 lines
1.9 KiB

  1. # recursive-readdir
  2. [![Build Status](https://travis-ci.org/jergason/recursive-readdir.svg?branch=master)](https://travis-ci.org/jergason/recursive-readdir)
  3. Recursively list all files in a directory and its subdirectories. It does not list the directories themselves.
  4. Because it uses fs.readdir, which calls [readdir](http://linux.die.net/man/3/readdir) under the hood
  5. on OS X and Linux, the order of files inside directories is [not guaranteed](http://stackoverflow.com/questions/8977441/does-readdir-guarantee-an-order).
  6. ## Installation
  7. npm install recursive-readdir
  8. ## Usage
  9. ```javascript
  10. var recursive = require("recursive-readdir");
  11. recursive("some/path", function (err, files) {
  12. // `files` is an array of file paths
  13. console.log(files);
  14. });
  15. ```
  16. It can also take a list of files to ignore.
  17. ```javascript
  18. var recursive = require("recursive-readdir");
  19. // ignore files named "foo.cs" or files that end in ".html".
  20. recursive("some/path", ["foo.cs", "*.html"], function (err, files) {
  21. console.log(files);
  22. });
  23. ```
  24. You can also pass functions which are called to determine whether or not to
  25. ignore a file:
  26. ```javascript
  27. var recursive = require("recursive-readdir");
  28. function ignoreFunc(file, stats) {
  29. // `file` is the path to the file, and `stats` is an `fs.Stats`
  30. // object returned from `fs.lstat()`.
  31. return stats.isDirectory() && path.basename(file) == "test";
  32. }
  33. // Ignore files named "foo.cs" and descendants of directories named test
  34. recursive("some/path", ["foo.cs", ignoreFunc], function (err, files) {
  35. console.log(files);
  36. });
  37. ```
  38. ## Promises
  39. You can omit the callback and return a promise instead.
  40. ```javascript
  41. readdir("some/path").then(
  42. function(files) {
  43. console.log("files are", files);
  44. },
  45. function(error) {
  46. console.error("something exploded", error);
  47. }
  48. );
  49. ```
  50. The ignore strings support Glob syntax via
  51. [minimatch](https://github.com/isaacs/minimatch).