@pkemp/dirtraverse

Recursive traversal of directory structure with a callback function

Usage no npm install needed!

<script type="module">
  import pkempDirtraverse from 'https://cdn.skypack.dev/@pkemp/dirtraverse';
</script>

README

Dirtraverse

Traverse directory and call a callback with each file/folder. If callback return true for a folder, it's content will be skipped.

Example

const dirtraverse = require('@pkemp/dirtraverse');

dirtraverse.traverse('.', (err, filepath, stats) => {
  console.log('Callback called with path: ', filepath);
  return stats.isDirectory() && path.basename(filepath) === '.git'	// return true if you want to skip traversal of a subfolder
});

See API docs for more information.

Thanks