Get the list of examples from the example directory.

@param {String} dirName - Name of the directory to read.
@param {Function} callback - Function to execute for each example.

@returns {undefined} Nothing.
359195
function getExamples(dirName, callback) {
  const example_files = fs.readdirSync(dirName);
  const entries = {};

  // iterate through the list of files in the directory.
  for (const filename of example_files) {
    // ooo, javascript file!
    if (filename.endsWith('.js')) {
      // trim the entry name down to the file without the extension.
      const entry_name = filename.split('.')[0];
      callback(entry_name, path.join(dirName, filename));
    }
  }

  return entries;
}
206447
function searchFile(name, dirList, callback) {
  if (typeof dirList === 'function') {
    callback = dirList;
    dirList = '';
  }

  if (dirList === undefined) {
    dirList = ''
  }

  if (!Array.isArray(dirList)) {
    dirList = [dirList];
  }

  var success = dirList.some(function(dir) {
    if (!dir) {
      return false;
    }
    try {
      /**
       * Don't try to optimise this to be async since any failures will be
       * passed back to the caller:
       */

      var data = fs.readFileSync(path.join(dir, name), 'utf8');

      callback(null, data);
      return true;
    } catch (e) {
      return false;
    }
  });

  if (!success) {
    return callback('Failed to find file \'' + name + '\' at specified locations:' + dirList.join(','));
  }
}
803056
function inspect(callback) {
  return function (filename) {
    var chunks = [];

    function transform(chunk, encoding, done) {
      /* jshint validthis:true */
      chunks.push(chunk);
      this.push(chunk);
      done();
    }

    function flush(done) {
      callback(filename, chunks.join(''), done);
      if (callback.length < 3) {
        done();
      }
    }

    return through(transform, flush);
  }
}
189762
function(callback) {

			var fileLoop = function(currentDir,templateDirectories,cb) {
				var callback_has_been_called = false
				fs.readdir(currentDir,function(err,files) {
					if (err) {
						return console.log('Unable to find files in path',currentDir)
					}
					var num = files.length

					var finishFile = function(i) {
						if (!(--num)) {
							if (!callback_has_been_called) {
								callback_has_been_called = true
								return cb()
							}
						} else {
							buildFileData(i+1)
						}
					}

					var buildFileData = function(i) {
						var file = files[i]
						var filepath = currentDir + '/' + file

						fs.stat(filepath,function(err2,stats) {
							if (err2) {
								return console.log('Unable to find file',filepath)
							}

							if (stats && stats.isDirectory()) {
								var pugatizerPath = '    puglatizer' + currentDir.replace(templateDirectories,'').replace(/\//g,'"]["') + '"]["' + file.replace('.pug','') + '"] = {}\r\n'
								pugatizerPath = pugatizerPath.replace('puglatizer"]','puglatizer')
								fs.appendFileSync(outputFile,pugatizerPath)
								fileLoop(filepath,templateDirectories,function() {
									finishFile(i)
								})
							} else if (stats && stats.isFile()) {
								var ext = path.extname(filepath)
								if (ext == '.pug') {
									var pugatizerPath = '    puglatizer' + currentDir.replace(templateDirectories,'').replace(/\//g,'"]["') + '"]["' + file.replace('.pug','') + '"] = '
									pugatizerPath = pugatizerPath.replace('puglatizer"]','puglatizer')
									buildTemplateFromFile(filepath,options,function(err,template) {
										pugatizerPath += minify.js(template.toString()) + ';\r\n\r\n'
										fs.appendFileSync(outputFile,pugatizerPath)
										finishFile(i)
									})
								} else {
									finishFile(i)
								}
							} else {
								finishFile(i)
							}
						})
					}

					if (!num) {
						return console.log('Unable to find files in path',currentDir)
					} else {
						buildFileData(0)
					}

				})

			}
			
			fileLoop(templateDirectories,templateDirectories,function() {
				return callback()
			})
		}
1254020
function readDirectoryFiles(directory) {
  return new Promise((resolve, reject) => {
    fs.readdir(directory, (err, files) => {
      if (err) {
        reject(err);
        return;
      }

      const isFile = fileName => readFileStats(path.join(directory, fileName))
        .then((fstat) => {
          if (fstat.isFile()) {
            return fileName;
          }
          return null;
        });

      Promise.all(files.map(isFile))
        .then(fileList => resolve(fileList.filter(f => f !== null)))
        .catch(reject);
    });
  });
}
765223
function(callback) {
      fs.readdir(args['<directory>'], function(err, files) {
        // error here means it does not exist, which is good.
        if (err || args['--force']) {
          return callback(null, args['<directory>']);
        }
        if (files.length > 0) {
          return callback(new Error(format('destination '
            + 'directory %s is not empty.', path.resolve(args['<directory>']))));
        }
        return callback(null, args['<directory>']);
      });
    }
1127157
function _getSafeFileName(filename, directory) {
        var deferred = q.defer();
    
        fs.readdir(directory, function(err, files) {
    
            if(err) {
              // This means the directory doesn't exist
              if (err.errno === 34 && err.code === 'ENOENT') {
                deferred.resolve(filename);
              }
              else {
                deferred.reject(err);
              }
            }
            else {
              var index = files.indexOf(filename);
              if (index > -1) { 
    
                // Get filename and extension (if it has one)
                var name, extension;
                var splitString = filename.split('.');
    
                // Has extension
                if (splitString.length > 1) {
                  extension = splitString.pop(); 
                  name = splitString.join('.');
    
                  // Wait! Is this a hidden file?
                  if (!name) {
                    name = '.' + extension;
                    extension = '';
                  }
                }
                // No extension
                else {
                  name = filename;
                  extension = '';
                }
    
                // Get the copy number appended to the name and increment, if any
                var matches = name.match(/\((\d+)\)$/);
                if (matches) {
                  var copyNumber = Number(matches[1]) + 1;
                  name = name.replace(/\((\d+)\)$/, '(' + copyNumber + ')'); 
                }
                else {
                  name += '(1)';
                }
    
                // Assemble new filename
                if (extension) {
                  filename = name + '.' + extension;
                }
                else {
                  filename = name;
                }
    			deferred.resolve(_getSafeFileName(filename, directory));
              }
    		  else {
              	deferred.resolve(filename);
    		  }
            }       
          });
    
        return deferred.promise;
      }
1078817
function readDirSync (dir, allFiles = []) {
  const files = fs.readdirSync(dir).map(f => join(dir, f))
  allFiles.push(...files)
  files.forEach(f => {
    fs.statSync(f).isDirectory() && readDirSync(f, allFiles)
  })
  return allFiles
}
413874
def list_js_files(dir):
    
    for dirpath, dirnames, filenames in os.walk(dir):
        for filename in filenames:
            if is_js_file(filename):
                yield os.path.join(dirpath, filename)
931549
function(callback) {
		var self = this;
		var sections = [Path.join("/")];
		var paths_to_traverse = [];

		var should_exclude = function(entry) {
			return entry[0] === "." || entry[0] === "_" || entry === "shared";
		};

		var traverse_path = function() {
			var current_path = paths_to_traverse.shift() || "";
			Fs.readdir(Path.join(self.contentDir, current_path), function(err, entries) {
				if (err) {
					throw err;
				}

				var run_callbacks = function() {
					if (entries.length) {
						return next_entry();
					} else if (paths_to_traverse.length) {
						return traverse_path();
					} else {
						return callback(sections);
					}
				};

				var next_entry = function() {
					var current_entry = entries.shift();
					if (should_exclude(current_entry)) {
						return run_callbacks();
					}

					var current_entry_path = Path.join(current_path, current_entry);
					Fs.stat(Path.join(self.contentDir, current_entry_path), function(err, stat) {
						if (err) {
							return run_callbacks();
						}

						if (stat.isDirectory()) {
							sections.push(Path.join("/",current_entry_path));
							paths_to_traverse.push(current_entry_path);
						}

						return run_callbacks();
					});
				};

				return run_callbacks();
			});
		};
		return traverse_path();
	}
540122
def get_examples(examples_dir="examples/"):  # pragma: no cover
    """"""
    all_files = os.listdir(examples_dir)
    python_files = [f for f in all_files if is_python_file(f)]
    basenames = [remove_suffix(f) for f in python_files]
    modules = [import_module(module) for module in pathify(basenames)]
    return [
        module for module in modules
        if getattr(module, 'app', None) is not None
    ]
1013988
function(replace, count, callback) {
    return pathmap.replace(
      pathmap.dirname(this, count), replace, callback);
  }
1310768
function commandExamples(examples) {
  if (!examples || !examples.length) {
    return ''
  }
  let exampleRender = `**Examples**${newLine}`
  exampleRender += '\`\`\`bash\n'
  examples.forEach((ex) => {
    console.log('ex', ex)
    exampleRender += `${ex}\n`
  })
  exampleRender += `\`\`\`${newLine}`
  return exampleRender
}
311699
function getComponentsWithExamples(root) {
    const componentsPath = `${__dirname}/../${root}/components`;
    return fs.readdirSync(componentsPath).map(component => ({
        name: component,
        sources: [`${componentsPath}/${component}`, `${componentsPath}/${component}/examples`]
    })).filter(isDirectory).map(obj => obj.name);
}
575544
def examples_dir( f = nil )
      if File.exists?( config_file_path )
        form_file_name( examples_dir_from_config_file, f )
      else
        form_file_name( config_dir( '/examples' ), f )
      end
    end
101826
function (directory, callback) {
        var that = this;
        fs.readdir(directory, function (err, files) {
            async.map(files, function langdir_iterator(file, next) {
                file = path.join(directory, file);
                fs.stat(file, function (err, stats) {
                    if (err || !stats.isDirectory()) return next(err);
                    var l = path.basename(file);
                    fs.readdir(file, function (err, files) {
                        if (err) return next(err);
                        async.map(files, function podir_iterator(file, next) {
                            file = path.join(directory, l, file);
                            fs.stat(file, function (err, stats) {
                                if (err || !stats.isFile()) return next(err);
                                that.loadLanguageFile(file, l, next);
                            });
                        }, next);
                    });
                });
            }, function langdir_done(err, results) {
                callback && callback(err);
            });
        });
    }
469634
function getInputSources(dirname, exclude, include, focusContractPath, callback) {
  let filesRead = 0;
  const sources = {};

  // get all file names
  dir.files(dirname, (filesError, files) => {
    if (filesError) {
      throwError(`while while getting input sources ${filesError}`);
    }

    // if no files in directory, then fire callback with empty sources
    if (files.length === 0) {
      callback(null, sources);
    } else {
      // read all files
      dir.readFiles(dirname, (readFilesError, content, filename, next) => {
        if (readFilesError) {
          throwError(`while getting input sources ${readFilesError}`);
        }

        // parsed filename
        const parsedDirName = dirname.replace('./', '');
        const parsedFileName = filename.replace(parsedDirName, '').replace(/^\//, '');
        const onlyFilename = filename.substr(filename.lastIndexOf('/') + 1);

        // add input sources to output
        if (filename.substr(filename.lastIndexOf('.') + 1) === 'sol'
          && filenameInclude(filename, exclude, include)
          && onlyFilename.charAt(0) !== '~'
          && onlyFilename.charAt(0) !== '#'
          && onlyFilename.charAt(0) !== '.') {
          sources[parsedFileName] = content;
        }

        // increase files readFiles
        filesRead += 1;

        // process next file
        if (filesRead === files.length) {
          // filter sources by focus dependencies
          if (focusContractPath) {
            callback(null, buildDependantsSourceTree(focusContractPath, sources));
          } else {
            callback(null, sources);
          }
        } else {
          next();
        }
      });
    }
  });
}