Parses a directory (will be then iteratively called for all subdirectories) or loads a file.
@param options
@param iterationInfo
@returns {{}}
5702
function (options, iterationInfo) {
        var files;
        var modules = {};

        // check if the counter has reached the desired depth indicated in options.depth
        if (typeof options.depth !== 'undefined' &&
            iterationInfo.currentDepth >= options.depth) {
            return;
        }

        // remember the starting directory
        try {
            files = fs.readdirSync(iterationInfo.dirName);
        } catch (e) {
            if (options.optional)
                return {};
            else
                throw new Error('Directory not found: ' + iterationInfo.dirName);
        }

        // iterate through files in the current directory
        files.forEach(function (fileName) {
            iterationInfo.fileName = fileName;
            //get absolute path
            iterationInfo.absolutePath = rtrim(iterationInfo.dirName, '/');
            iterationInfo.absoluteFullPath = iterationInfo.absolutePath + '/' + fileName;
            //get relative path
            iterationInfo.relativePath = iterationInfo.absolutePath.replace(iterationInfo.initialDirName, '');
            iterationInfo.relativeFullPath = iterationInfo.absoluteFullPath.replace(iterationInfo.initialDirName, '');
            // make sure a slash exists on the left side of relative paths
            iterationInfo.relativePath = '/' + ltrim(iterationInfo.relativePath, '/');
            iterationInfo.relativeFullPath = '/' + ltrim(iterationInfo.relativeFullPath, '/');

            if (fs.statSync(iterationInfo.absoluteFullPath).isDirectory()) {
                processDirectory(options, iterationInfo, modules)
            }
            else {
                processFile(options, iterationInfo, modules);
            }
        });

        return modules;
    }
1266285
function _mkdirpSync (directory, mode) {

			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 mode && "number" !== typeof mode) {
				throw new TypeError("\"mode\" argument is not a number");
			}
			else if (!isDirectorySync(directory)) {

				const SUB_DIRECTORY = dirname(directory);

				if (!isDirectorySync(SUB_DIRECTORY)) {
					_mkdirpSync(SUB_DIRECTORY);
				}

				mkdirSync(directory, mode ? mode : DEFAULT_OPTION);

			}

		}
1075803
function pathParser(root, extname, subPath, paths) {
  var dirPath = path.resolve(subPath || root);
  var files;
  paths = paths || {};

  try {
    files = fs.readdirSync(dirPath);
  } catch(e) {
    files = [];
  }
  files.forEach(function(file) {
    file = path.join(dirPath, '/', file);
    if (fs.statSync(file).isFile()) {
      if (~extname.split('|').indexOf(path.extname(file).substr(1))) {
        var rootPath = '^' + path.join(path.resolve(root), '/');
        rootPath = rootPath.replace(/\\/g, '\\\\') + '(.*)\.(' + extname + ')$';
        paths[file.match(new RegExp(rootPath))[1].toLowerCase()] = file;
      }
    } else if (fs.statSync(file).isDirectory()) {
      pathParser(root, extname, file, paths);
    }
  });
  return paths;
}
365711
def _parse_directory(self):
        
        if self._parser.has_option('storage', 'directory'):
            directory = self._parser.get('storage', 'directory')
            # Don't allow CUSTOM_APPS_DIR as a storage directory
            if directory == CUSTOM_APPS_DIR:
                raise ConfigError("{} cannot be used as a storage directory."
                                  .format(CUSTOM_APPS_DIR))
        else:
            directory = MACKUP_BACKUP_PATH

        return str(directory)
611669
function readDir(err, files) {
  if (err) {
    internalServerError.call(this, err);
  } else {
    var dirName = decodeURIComponent(
      getCurrentPathName(this)
    );
    this.output.push(
      "<!doctype html>",
      "<html>",
        "<head>",
          "<title>Index of ", dirName, "</title>",
          '<meta name="viewport" content="',
            'width=device-width,',
            'initial-scale=1.0,',
            'maximum-scale=1.0,',
            'user-scalable=no',
          '"/>',
          '<meta name="generator" content="polpetta" />',
        "</head>",
        "<body>",
          "<strong>Index of " + dirName + "</strong>",
          "<ul>"
    );
    if (dirName != WEB_SEP) {
      this.output.push(
        '<li><a href="..">..</a></li>'
      );
    }
    files.forEach(readDir.forEach, this.output);
    this.output.push(
          "</ul>",
        "</body>",
      "</html>"
    );
    this.output.flush(200, "text/html", "utf-8");
  }
}
300363
function loadMappings(rootDir, paths) {
        var mappings = {}, i, j, fullPath, fileNames, fileName, path, name, val;

        if (!paths) {
            return mappings;
        }

        for (i = 0; i < paths.length; i++) {
            path = paths[i];
            fullPath = rootDir + '/' + path;

            // if the directory doesn't exist, then skip to the next loop iteration
            if (!fs.existsSync(p.normalize(fullPath))) {
                continue;
            }

            // loop through all files in this folder
            fileNames = fs.readdirSync(p.normalize(fullPath));

            for (j = 0; j < fileNames.length; j++) {
                fileName = fileNames[j];

                // if it is a javascript file and it DOES NOT end in .service.js, then save the mapping
                if (utils.isJavaScript(fileName) && !fileName.match(/^.*\.service\.js$/)) {
                    name = utils.getCamelCase(fileName);
                    val = utils.getModulePath(path, fileName);
                    mappings[name] = val;
                    mappings[name.substring(0, 1).toUpperCase() + name.substring(1)] = val;  // store PascalCase as well
                }

                // else if we are dealing with a directory, recurse down into the folder
                else if (fs.lstatSync(p.join(fullPath, fileName)).isDirectory()) {
                    _.extend(mappings, this.loadMappings(rootDir, [path + '/' + fileName]));
                }
            }
        }

        return mappings;
    }
912677
private void parseDirectoryFiles(WsResource directory, ServerConfiguration configuration) throws ConfigParserException, ConfigValidationException {
        if (directory != null) {
            File[] defaultFiles = getChildXMLFiles(directory);
            if (defaultFiles == null)
                return;

            Arrays.sort(defaultFiles, new AlphaComparator());

            for (int i = 0; i < defaultFiles.length; i++) {
                File file = defaultFiles[i];
                if (!file.isFile())
                    continue;

                WsResource defaultFile = directory.resolveRelative(file.getName());
                if (defaultFile == null) {
                    // This should never happen, but it's conceivable that someone could remove a file
                    // after listFiles and before getChild
                    if (tc.isDebugEnabled()) {
                        Tr.debug(tc, file.getName() + " was not found in directory " + directory.getName() + ". Ignoring. ");
                    }
                    continue;
                }
                Tr.audit(tc, "audit.dropin.being.processed", defaultFile.asFile());
                try {
                    parser.parseServerConfiguration(defaultFile, configuration);
                } catch (ConfigParserException ex) {
                    parser.handleParseError(ex, null);

                    if (ErrorHandler.INSTANCE.fail()) {
                        // if onError=FAIL, bubble the exception up the stack
                        throw ex;
                    } else {
                        // Mark the last update for the configuration so that we don't try to load it again
                        configuration.updateLastModified(configRoot.getLastModified());
                    }
                }
            }
        }
    }
43582
private static void checkSrcOption(String[] args)
        throws ProblemException {
        Set<File> dirs = new HashSet<File>();
        for (int i = 0; i<args.length; ++i) {
            if (args[i].equals("-src")) {
                if (i+1 >= args.length) {
                    throw new ProblemException("You have to specify a directory following -src.");
                }
                StringTokenizer st = new StringTokenizer(args[i+1], File.pathSeparator);
                while (st.hasMoreElements()) {
                    File dir = new File(st.nextToken());
                    if (!dir.exists()) {
                        throw new ProblemException("This directory does not exist: "+dir.getPath());
                    }
                    if (!dir.isDirectory()) {
                        throw new ProblemException("\""+dir.getPath()+"\" is not a directory.");
                    }
                    if (dirs.contains(dir)) {
                        throw new ProblemException("The src directory \""+dir.getPath()+"\" is specified more than once!");
                    }
                    dirs.add(dir);
                }
            }
        }
        if (dirs.isEmpty()) {
            throw new ProblemException("You have to specify -src.");
        }
    }
987054
function getDirectoryTree(dir) {
    const items = [];
    return new Promise(function(resolve) {
        fs.walk(dir)
        .on('data', function (item) {
            items.push(item.path);
        })
        .on('end', function () {
            resolve(items);
        });
    });
}
72319
function (options, iterationInfo, modules) {
        // filename filter
        if (options.fileNameFilter) {
            var match = iterationInfo.fileName.match(options.fileNameFilter);
            if (!match) {
                return;
            }
        }

        // Filter spec.js files
        var match = iterationInfo.fileName.match(/.spec.js/i);
        if (match) {
            return;
        }

        // relative path filter
        if (options.relativePathFilter) {
            var pathMatch = iterationInfo.relativeFullPath.match(options.relativePathFilter);
            if (!pathMatch)
                return;
        }

        //load module
        loadModule(modules, options, iterationInfo);
    }
1359355
public void parse(final String filename, final File dir) {
        filePath = stripFragment(filename);
        dirPath = dir;
        try {
            final File f = new File(dir, filePath);
            reader.setErrorHandler(new DITAOTXMLErrorHandler(f.getAbsolutePath(), logger));
            logger.info("Processing " + f.getAbsolutePath());
            reader.parse(f.toURI().toString());
        } catch (final RuntimeException e) {
            throw e;
        } catch (final Exception e) {
            throw new RuntimeException("Failed to parse " + filename + ": " + e.getMessage(), e);
        }
    }
1099201
def parser
      OptionParser.new do |parser|
        parser.summary_width = 34

        parser.banner = "Usage: tune [options]\n\n"

        parser.on('--init [PATH]',
                  'Create framework folder structure') do |dir|
          base_path = dir || 'lib'
          %w[groups pages steps].each do |folder|
            FileUtils.mkdir_p(base_path)
            path = "#{base_path}/#{folder}"
            exists = directory_exists?(path)
            print_directory(path, exists)
            create_directory(path) unless exists
          end
        end
      end
    end
818779
public function with($iteration) {
        return $this
        ->fold(
            array(), 
            function($a, $f) use ($iteration) { 
                $iteration($f); 
                // As the subjacent FDirectory is lazy, we need to evaluate
                // the contents, as there might be additional computations
                // hidden.
                if (!$f->isFile()) {
                    $f->contents();
                }
                $a[] = $f; // Do not disturb the structure of
                return $a; // the directory tree.
            }
        );
    }
1264835
function _rmdirpSync (directory) {

			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 (isDirectorySync(directory)) {

				readdirSync(directory).forEach((_file) => {

					const file = join(directory, _file);

					if (isDirectorySync(file)) {
						_rmdirpSync(file);
					}
					else {
						unlinkSync(file);
					}

				});

				rmdirSync(directory);

			}

		}
481992
function loadTemplates (dirs, options) {
    // require dirs to be array
    if (!Array.isArray(dirs)) {
        dirs = [dirs]
    }
    // templates indexed by absolute file name
    var templates = {}
    // load all templates in all directories
    return Promise.each(dirs, dir => {
        // load all files under dir
        return globby('**/*'+GLOBAL.ext, {
            cwd: dir,
            follow: true,
        })
        // compile templates for files
        .then(files => {
            return loadTemplatesFiles(dir, files, options, templates)
        })
    })
    // resolve with templates
    .then(() => templates)
}
592424
function loadTasks(dir) {
    /**
     * Resolve any relative paths
     *
     * @type    {String}
     */
    dir = require('path').resolve(dir);

    /**
     * Interal collection of modules loaded
     *
     * @type    {Object}
     */
    var modules = {};

    /**
     * Get a list of items in a directory. This is synchronous since we're
     * only doing this once on application load
     *
     * @type    {Array}
     */
    var list = require('fs').readdirSync(dir);

    /**
     * Setup the Regex to filter out *.js files but exclude files with
     * multiple `.` in them
     *
     * @type    {RegExp}
     */
    var jsFileTest = /^\w+\.js$/i;

    // Cycle through each item in the directory
    list.forEach(function(module) {
      //Check to see if with have a match and if we split it apartment
      if (jsFileTest.test(module)) {
        // If we find a match try to load and save it. Otherwise log an error
        try {
          modules[module] = require(dir + '/' + module);
        } catch (err) {
          console.error('Unable to load ' + dir + '/' + module, err);
        }
      }
    });

    return modules;
  }
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);
}