# io/index.js

    1// Copyright 2013 Selenium committers2// Copyright 2013 Software Freedom Conservancy3//4// Licensed under the Apache License, Version 2.0 (the "License");5// you may not use this file except in compliance with the License.6//     You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing, software11// distributed under the License is distributed on an "AS IS" BASIS,12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.13// See the License for the specific language governing permissions and14// limitations under the License.1516var fs = require('fs'),17    path = require('path');181920var PATH_SEPARATOR = process.platform === 'win32' ? ';' : ':';212223// PUBLIC API242526/**27 * Searches the {@code PATH} environment variable for the given file.28 * @param {string} file The file to locate on the PATH.29 * @param {boolean=} opt_checkCwd Whether to always start with the search with30 *     the current working directory, regardless of whether it is explicitly31 *     listed on the PATH.32 * @return {?string} Path to the located file, or {@code null} if it could33 *     not be found.34 */35exports.findInPath = function(file, opt_checkCwd) {36  if (opt_checkCwd) {37    var tmp = path.join(process.cwd(), file);38    if (fs.existsSync(tmp)) {39      return tmp;40    }41  }4243  var dirs = process.env['PATH'].split(PATH_SEPARATOR);44  var found = null;45  dirs.forEach(function(dir) {46    var tmp = path.join(dir, file);47    if (!found && fs.existsSync(tmp)) {48      found = tmp;49    }50  });51  return found;52};