Execute a callback for each file in a directory
179452
function foreachInDir (dirpath, fnc, done) {
	// Read the files
	fs.readdir(dirpath, function (err, files) {
		// Return error
		if (err) {
			return done(err);
		}

		// Process each file
		parallel(files.map(function (f) {
			return fnc.bind(null, f);
		}), done);
	});
}
677250
function makeDirectories(dirs, callback) {
  var mkdir = function(dir, mkCallback) {
    exec('mkdir -p ' + dir, function(err, stdout, stderr) {
      return mkCallback(err);
    });
  };

  async.forEach(dirs, mkdir, callback);
}
985208
function(callback) {
            if (!file.isDirectory()) {
              callback();
              return;
            }

            grunt.log.write(wrap('d--------- /' + file.dest));
            ftpout.raw.mkd(file.dest, function(err) {
              if (err) {
                if (err.code != 550) {
                  done(err);
                } else {
                  grunt.log.writeln(wrapRight('[PRESENT]').yellow);
                }
              } else {
                grunt.log.writeln(wrapRight('[SUCCESS]').green);
              }
              callback();
            });
          }
897887
function(callback){
    var argFiles,
        filePath,
        i;

    if(!program.files || program.files.length === 0){
        return callback(null, true);
    }

    argFiles = program.files.split(',');

    output("Loading files...");

    for(i=0; i<argFiles.length; i++){
        filePath = path.resolve(__dirname, argFiles[i].toString());
        output("Reading file..." + filePath);
        if(fs.existsSync(filePath)){
            files.push(fs.readFileSync(filePath));
        }else{
            return callback("File does not exist, " + filePath, false);
        }
    }

    callback(null, true);
}
572703
function trigger(context, path, data) {
    if (util.isFunction(_hooksCallbacks[path])) {
        _hooksCallbacks[path].call(context, data, context);
    }
}
997946
function findSync(dir, callback) {
	var rootStat = fs.statSync(dir);
	if (!rootStat.isDirectory()) {
		if (callback) callback(dir, rootStat);
		return [dir];
	}

	return fs.readdirSync(dir).reduce(function(files, file) {
		var p = path.join(dir, file),
			stat = fs.statSync(p);
		if (callback) callback(p, stat);
		files.push(p);

		if (stat.isDirectory()) {
			files.push.apply(files, findSync(p, callback));
		}

		return files;
	}, []);
}
483926
static function chdir($dir, $callback = null, $argv = array())
    {
        if (!is_dir($dir)) {
            throw new \InvalidArgumentException("$dir does not exist.");
        }

        $cwd = getcwd();
        chdir($dir);

        if (null === $callback) {
            return;
        }

        $returnValue = call_user_func_array($callback, $argv);

        chdir($cwd);
        return $returnValue;
    }
517968
def watch(directory=None, auto_clear=False, extensions=[]):
    """"""
    if directory and not os.path.isdir(directory):
        raise ValueError('Directory not found: ' + directory)
    directory = os.path.abspath(directory)

    # Initial run
    event_handler = ChangeHandler(directory, auto_clear, extensions)
    event_handler.run()

    # Setup watchdog
    observer = Observer()
    observer.schedule(event_handler, path=directory, recursive=True)
    observer.start()

    # Watch and run tests until interrupted by user
    try:
        while True:
            time.sleep(1)
    except KeyboardInterrupt:
        observer.stop()
    observer.join()
19565
function maybeMkdir(path, opts, callback) {
  if (typeof opts === 'function') {
    callback = opts;
    opts = null;
  }

  fs.exists(path, function(exists) {
    if (opts && opts.purge) {
      rimraf.sync(path);
    } else {
      if (exists) {
        return callback && callback();
      }
    }

    (function tryMkdir() {
      fs.mkdir(path, function(err) {
        if (err) {
          // TODO(gaye): Eventually we should give up.
          debug('error maybeMkdir, will try again ' + path + ': ' + err);
          return tryMkdir();
        }

        return callback(null);
      });
    })();
  });
}
798532
function(callback) {

				// build a list of individual files
				var rasterFiles =	[];
				task.files.forEach(function(file) {
					if (!grunt.file.isDir(file.src[0]) && path.extname(file.dest).toLowerCase() !== '.svg') {
						rasterFiles.push(file.src[0]);
					}
				});

				// if there’s anything to optimize…
				if (rasterFiles.length > 0) {

					// get absolute paths to the stuff we’re optimizing
					var rasterFilesResolved = rasterFiles.map(function(dir) {
						return path.resolve(__dirname, '../' + dir);
					});

					// optimize as many times as the user wants
					async.timesSeries(options.optimize.input.picopt, function(i, next) {

						// let the user know that we’re optimizing inputs
						grunt.log.writeln('Optimizing inputs with picopt (pass ' + (i + 1) + ' of ' + options.optimize.input.picopt + ')…');

						// do the optimizations (with promises)
						optimizePicopt(rasterFilesResolved, binPath.picopt).then(function() {
							next();
						});

					}, callback);

				} else {
					callback(null);
				}

			}
24418
function (filepath, options, callback) {
        if (typeof options === 'function') {
            callback = options;
            options = undefined;
        }

        options = options || '';
        var args = _.compact([filepath].concat(options.replace(/\ \ /g, ' ').split(' ')));

        logger.debug('cmd:', constant.PROG_OPTIPNG, args.join(' '));

        var proc = spawn(constant.PROG_OPTIPNG, args);

        proc.stdout.on('data', function (data) {
            logger.debug(data.toString());
        });

        proc.stderr.on('data', function (data) {
            logger.debug(data.toString());
        });

        proc.addListener('exit', function (e) {
            if (e) {
                return callback(e);
            }
            callback();
        });
    }
1068008
function _mkdirp (directory, mode, callback) {

			if ("undefined" === typeof directory) {
				throw new ReferenceError("missing \"directory\" argument");
			}
				else if ("string" !== typeof directory) {
					throw new TypeError("\"directory\" argument is not a string");
				}
				else if ("" === directory.trim()) {
					throw new Error("\"directory\" argument is empty");
				}
			else if ("undefined" !== typeof callback && "number" !== typeof mode) {
				throw new TypeError("\"mode\" argument is not a number");
			}
			else if ("undefined" === typeof callback && "undefined" === typeof mode) {
				throw new ReferenceError("missing \"callback\" argument");
			}
				else if ("function" !== typeof callback && "function" !== typeof mode) {
					throw new TypeError("\"callback\" argument is not a function");
				}
			else {

				let _callback = callback;
				let _mode = mode;

				if ("undefined" === typeof _callback) {
					_callback = mode;
					_mode = DEFAULT_OPTION;
				}

				isDirectoryProm(directory).then((exists) => {

					return exists ? Promise.resolve() : Promise.resolve().then(() => {

						const SUB_DIRECTORY = dirname(directory);

						return isDirectoryProm(SUB_DIRECTORY).then((_exists) => {

							return _exists ? new Promise((resolve, reject) => {

								mkdir(directory, _mode, (err) => {
									return err ? reject(err) : resolve();
								});

							}) : new Promise((resolve, reject) => {

								_mkdirp(SUB_DIRECTORY, _mode, (err) => {

									return err ? reject(err) : mkdir(directory, _mode, (_err) => {
										return _err ? reject(_err) : resolve();
									});

								});

							});

						});

					});

				}).then(() => {
					_callback(null);
				}).catch(callback);

			}

		}
1240769
public function each($callback)
    {
        for ($i = 0; $i < $this->archive->numFiles; ++$i) {
            //skip if folder
            $stats = $this->archive->statIndex($i);
            if ($stats['size'] === 0 && $stats['crc'] === 0) {
                continue;
            }
            call_user_func_array($callback, [
                'file' => $this->archive->getNameIndex($i),
                'stats' => $this->archive->statIndex($i)
            ]);
        }
    }
1114063
function execDir(path, options) {
    var rawFiles = [];

    function pushFile(file, data) {
      rawFiles.push({
        file: file,
        data: data
      });
    }

    // Add in implied current and parent dirs.
    pushFile('.', fs.statSync('.'));
    pushFile('..', fs.statSync('..'));

    // Walk the passed in directory,
    // pushing the results into `rawFiles`.
    walkDir(path, pushFile, ls.error);

    var o = ls.execLsOnFiles(path, rawFiles, options);
    o.path = path;
    return o;
  }
1207712
function processDir(options, callback) {
  return fs.readdir(options.path, function(err, filenames) {
    if (err) {
      return callback(err);
    }

    if (options.ignoreDotFiles) {
      filenames = _.filter(filenames, function(filename) {
        return filename[0] !== ".";
      });
    }

    return async.map(filenames, function(filename, done) {
      const abspath = path.join(options.path, filename);

      if (options.statEach === false) {
        return done(null, {
          filename,
          path: abspath,
        });
      }

      stat(abspath, function(statErr, stats) {
        if (statErr) {
          return done(statErr);
        }
        return done(null, stats);
      });
    }, function(mapErr, statsMap) {
      if (mapErr) {
        return callback(err);
      }

      if (!options.ignoreCurDir) {
        const stats = _.cloneDeep(options.dirStats);
        stats.filename = ".";
        statsMap.push(stats);
      }

      if (!options.ignoreUpDir) {
        const abspath = path.join(options.path, "..");
        return stat(abspath, function(statErr, stats) {
          if (err) {
            return callback(err);
          }
          stats.filename = "..";
          statsMap.push(stats);
          return callback(null, statsMap);
        });
      }

      return callback(null, statsMap);
    });
  });
}
141084
def execute(self):
        '''  '''

        # Create a temporary directory
        self.temp_dir = tempfile.mkdtemp()
        os.chdir(self.temp_dir)

        # Spin up the directory watcher
        DirWatcher(self.temp_dir, self.file_created)

        # Spin up tcpdump
        self.subprocess_manager(self.tcpdump_cmd)
519403
function _fireReadFileCallbacks(filename, data, error=false) {
  const callbacks = readFileCallbacks.get(filename);
  if (callbacks) {
    if (callbacks.size) callbacks.forEach(callback=>error?callback(data, null):callback(null, data));
    callbacks.clear();
    readFileCallbacks.delete(filename);
  }
}