How to use walk - 10 common examples

To help you get started, we’ve selected a few walk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github Azure / azure-xplat-cli / lib / commands / arm / apiapp / lib / packaging / dirops.js View on Github external
function removeDir(dir, done) {
  // Have to collect directories and delete them at the end
  // so we delete in proper order

  // path.resolve call normalizes forward and backslashes to match path.sep
  // as well as making path absolute.
  dir = path.resolve(dir);

  var dirs = [dir.split(path.sep)];
  var walker = walk.walk(dir);

  walker.on('files', function (root, stats, next) {
    var numFiles = stats.length;
    stats
      .map(function (stat) { return path.join(root, stat.name); })
      .forEach(function (file) {
        fs.unlink(file, function () {
          --numFiles;
          if (numFiles === 0) {
            next();
          }
        });
      });
  })
  .on('directory', function (root, stats, next) {
    var dirPath = path.resolve(path.join(root, stats.name));
github charliecalvert / JsObjects / JavaScript / NodeCode / MakeHtml / walker.js View on Github external
walker.walkDirs = function(directoryToWalk, extensionFilter, callback) {

	// var content = process.env.ELF_CONTENT;
	// console.log('walk called', walker.content);
	var walkInstance = walk.walk(directoryToWalk, walker.options);

	walkInstance.on("file", function (root, fileStats, next) {
		// console.log('file found', fileStats.name);
		var fileExtension = path.extname(fileStats.name);
		if(fileExtension === extensionFilter) {
			walker.fileReport.push({root: root, fileStats: fileStats});
		}
		next();
		/* fs.readFile(fileStats.name, function () { next(); }); */
	});

	walkInstance.on("errors", function (root, nodeStatsArray, next) {
		console.log(root, nodeStatsArray);
		next();
	});
github percy / react-percy / packages / react-percy-storybook / src / getStaticAssets.js View on Github external
if (fs.statSync(absolutePath).size > MAX_FILE_SIZE_BYTES) {
          // eslint-disable-next-line no-console
          console.warn('\n[percy][WARNING] Skipping large file: ', resourceUrl);
          return;
        }

        // TODO(fotinakis): this is synchronous and potentially memory intensive, but we don't
        // keep a reference to the content around so this should be garbage collected. Re-evaluate?
        const content = fs.readFileSync(absolutePath);

        hashToResource[encodeURI(resourceUrl)] = content;
        next();
      },
    },
  };
  walk.walkSync(buildDir, walkOptions);

  return hashToResource;
}
github jettro / nodejs-photo-indexer / app.js View on Github external
var exif = require('exif2');
var walk = require('walk');
var elasticsearch = require('elasticsearch');
var readline = require('readline');

var walker  = walk.walkSync('/Users/jettrocoenradie/Pictures/export/2013', { followLinks: false });

var client = new elasticsearch.Client({
	host: '192.168.1.10:9200',
	log:'trace'
});

walker.on('file', function(root, stat, next) {
	console.log("Walk " + stat.name);
    // Add this file to the list of files
    if (strEndsWith(stat.name.toLowerCase(),".jpg")) {
	    extractData(root + '/' + stat.name, next);
    }
    next();
});

walker.on('end', function() {
github ecomfe / htmlcs / lib / cli / helper.js View on Github external
return targets.reduce(function (files, target) {
        var stat = fs.statSync(target);

        if (stat.isFile()) {
            files.push(target);
            return files;
        }

        if (stat.isDirectory()) {
            walk.walkSync(target, {
                followLinks: false,
                filters: ['node_modules', 'bower_components', 'Temp', '_Temp'],
                listeners: {
                    file: function (root, fileStat, next) {
                        var filePath = path.join(root, fileStat.name);

                        // filter with suffix (.html)
                        if (HTML_EXT_PATTERN.test(filePath)) {
                            files.push(filePath);
                        }
                        next();
                    }
                }
            });
            return files;
        }
github charliecalvert / JsObjects / JavaScript / Games / Crafty06 / SendToS3.js View on Github external
function walkDirs(folderName) { 'use strict';
	var options = {
		followLinks : false,
	};

	var walker = walk.walk(folderName, options);


	walker.on("names", function(root, nodeNamesArray) {
		nodeNamesArray.sort(function(a, b) {
			if (a > b)
				return 1;
			if (a < b)
				return -1;
			return 0;
		});
	});

	walker.on("directories", function(root, dirStatsArray, next) {
		// dirStatsArray is an array of `stat` objects with the additional attributes
		// * type
		// * error
github animade / frontend-md / lib / filetree.js View on Github external
function render_code_folder_structure(folder, title, callback) {

  var folder_depth = 0; // Pointer to indicate how deep we've gone through the folders
  var folder_history = [];

  // ------------------------------------------------
  // Iterate through the folders
  //

  var files = [];

  // Walker options
  var walker = walk.walk(folder, {
    followLinks: false
  });

  // ------------------------------------------------
  // Open the code block
  //

  markdown_contents += "\n\n";
  markdown_contents += "### " + title;
  markdown_contents += "\n\n";
  markdown_contents += '````';
  markdown_contents += "\n";


  walker.on('file', function(root, stat, next) {
github LeonBlade / xnbcli / xnbcli.js View on Github external
output = path.join(path.dirname(input), path.basename(input, ext) + newExt); 
        }
        // output is a directory
        else if (fs.statSync(output).isDirectory())
            output = path.join(output, path.basename(input, ext) + newExt);

        // call the function
        return fn(input, output);
    }

    // output is undefined
    if (output == undefined)
        output = input;

    // get out grandpa's walker
    const walker = walk.walk(input);

    // when we encounter a file
    walker.on('file', (root, stats, next) => {
        // get the extension
        const ext = path.extname(stats.name).toLocaleLowerCase();
        // skip files that aren't JSON or XNB
        if (ext != '.json' && ext != '.xnb')
            return next();

        // swap the input base directory with the base output directory for our target directory
        const target = root.replace(input, output);
        // get the source path
        const inputFile = path.join(root, stats.name);
        // get the target ext
        const targetExt = ext == '.xnb' ? '.json' : '.xnb';
        // form the output file path
github poooi / poi / build / compile-to-js.es View on Github external
return new Promise(resolve => {
    const tasks = []
    walk
      .walk(appDir, options)
      .on('file', (root, fileStats, next) => {
        const extname = path.extname(fileStats.name).toLowerCase()
        if (targetExts.includes(extname)) {
          tasks.push(async () => {
            const srcPath = path.join(root, fileStats.name)
            const tgtPath = changeExt(srcPath, '.js')
            // const src = await fs.readFile(srcPath, 'utf-8')
            let tgt
            try {
              const result = await promisify(transformFile)(srcPath, {
                presets,
                plugins,
              })
              tgt = result.code
            } catch (e) {
github yhat / rodeo / src / services / find-file.js View on Github external
module.exports = function (ws) {
  if (walker) {
    walker.pause();
  }

  let pref = preferences.getPreferences(),
    n = 0,
    wd = USER_WD;

  walker = walk.walk(USER_WD, { followLinks: false });

  // reindex file search
  walker = walk.walk(USER_WD, { followLinks: false });

  ws.sendJSON({ msg: 'file-index-start' });

  walker.on('file', function (root, stat, next) {

    // handles issue w/ extra files being emitted if you're indexing a large directory and
    // then cd into another directory
    if (wd != USER_WD) {
      return;
    }

    let dir = root.replace(USER_WD, '') || '',
      displayFilename = path.join(dir, stat.name).replace(/^\//, '');

walk

A node port of python's os.walk

(MIT OR Apache-2.0)
Latest version published 3 years ago

Package Health Score

59 / 100
Full package analysis

Popular walk functions