thecodrr / fdir

⚡ The fastest directory crawler & globbing library for NodeJS. Crawls 1m files in < 1s
https://thecodrr.github.io/fdir/
MIT License
1.51k stars 58 forks source link

How to search for a folder by its name and return the folder path? #34

Closed mark134340 closed 3 years ago

mark134340 commented 4 years ago

How to search for a folder by its name and return the folder path instead of returning all the parent directories?

const files = new fdir()
                    .withBasePath()
                    // .withDirs()
                    .withFullPaths()
                    // .glob("F:/CGLibrary/**/*Video*")
                    .filter((path) => path.indexOf("Video") != -1)
                    .crawl("F:/")
                    .sync();

                console.log(files);
thecodrr commented 4 years ago

Single folder search is not possible yet. I am working on adding it though. Perhaps in the next version?

thecodrr commented 3 years ago

This should now be possible as:

const files = new fdir()
  .onlyDirs()
  .filter((path) => {
    return path.endsWith("/composition/examples/src");
  })
  .crawl("node_modules")
  .sync();

console.log(files[0]);