Check if a file exists
@param {string} filePath path and filename: the file to control
@returns {Promise<string>} resolve with the filePath that exists
@throws {error} if the file doesn't exist
3837
function existFile(filePath, mode = fs.constants.W_OK) {
  return new Promise((resolve, reject) => {
    fs.access(filePath, mode, (err) => {
      if (err) {
        reject(err);
        return;
      }
      resolve(filePath);
    });
  });
}
1205473
function realRequirPath(filePath) {
  // console.log('realRequirPath:filePath: ' + filePath);
  var jsFilePath = filePath + '.js';
  if (fs.existsSync(filePath)) {
    if (fs.statSync(filePath).isDirectory()) {
      jsFilePath = filePath + '.js';
      if (fs.existsSync(jsFilePath)) {
        return jsFilePath;
      } else {
        jsFilePath = path.join(filePath, 'index.js');
      }
      // console.log('realRequirPath:jsFilePath: ' + jsFilePath);
    } else if (fs.statSync(filePath).isFile()) {
      return filePath;
    } else {
      return null;
    }
  } else {
    jsFilePath = filePath + '.js';
    // console.log('realRequirPath:filePath: ' + filePath);
  }

  if (fs.existsSync(jsFilePath)) {
    // console.log('realRequirPath:filePath: ' + filePath);
    return jsFilePath;
  } else {
    return null;
  }
}
3629
function exists(filepath) {
		var does = grunt.file.exists(filepath);
		if (!does) {
			grunt.log.error(
				'Human error: ' + chalk.cyan(filepath) + ' not found.'
			);
			grunt.fail.errorcount++;
		}
		return does;
	}
305322
async function loadConfigFile(filePath) {
  const f = await Promise.any(
    _.map(['.yml', '.yaml', '.json', ''], async(ext) =>
      await utils.fileExists(`${filePath}${ext}`)));
  if (f) {
    return loadYaml(await fs.readFileAsync(f));
  }
  return undefined;
}
446915
function existsSync (path) {
  try {
    Fs.accessSync(Path.resolve(path), Fs.F_OK)
    return true
  } catch (err) {
    return false
  }
}
1162993
function (fileName) {
            if (!file.exists(fileName)) {
                try {
                    //Try to find the path of the file thanks to node's require resolving.
                    fileName = nodeRequire.resolve(fileName);
                } catch(e) {}
            }
            return frontSlash(path.normalize(frontSlash(fs.realpathSync(fileName))));
        }
769404
function isPathAccessible (filePath) {
  try {
    fs.accessSync(filePath)
    debug(`Utils: isPathAccessible(): ${filePath} exists`)
    return true
  } catch (err) {
    debug(`Utils: isPathAccessible(): ${filePath} does not exist`)
    return false
  }
}
63697
function existence ( filepath ) {
		var does = grunt.file.exists ( filepath );
		if ( !does ) {
			grunt.log.warn ( filepath + " not found." );
		}
		return does;
	}
865962
function isDirectory(filePath) {
	var isDir = false;
	try {
		var absolutePath = path.resolve(filePath);
		isDir = fs.lstatSync(absolutePath).isDirectory();
	} catch (e) {
		isDir = e.code === 'ENOENT';
	}
	return isDir;
}
1332907
function(filepath, req, res) {
    var path = require("path"),
        config = module.exports.config,
        result = false,
        parentdir;
    do {
        var defaultdir = path.resolve(path.join(config.responsesdefault, filepath));
        parentdir = path.resolve(path.join(config.responses, filepath));
        if (isValidDir(parentdir) && isValidFile(path.join(parentdir, "index.js"))) {
            //Parent module response handler exists.
            require(parentdir)(req, res);
            result = true;
        } else if (isValidDir(defaultdir) && isValidFile(path.join(defaultdir, "index.js"))) {
            //Default response handler
            require(defaultdir)(req, res);
            result = true;
        }
        if (filepath === path.sep) break;
        filepath = path.dirname(filepath);
    } while (result === false && parentdir !== filepath);
    return result;
}
372861
def file_exists?(path)
      begin
        ret = self.quietly { ls(path) }
      rescue Rye::Err => ex
        ret = ex.rap
      end
      # "ls" returns a 0 exit code regardless of success in Linux
      # But on OSX exit code is 1. This is why we look at STDERR. 
      !(ret.exit_status > 0) || ret.stderr.empty?
    end
1292566
function fsRead(filePath) {
    return new Promise((resolve, reject) => {
        fs.readFile(filePath, (err, data) => {
            if (err) {
                if (err.syscall === 'open') {
                    console.log('Open "' + err.path +'" fail!')
                }
                reject(err);
            }
            resolve(data.toString())
        })
    })
}
202769
async function fileExists(f) {
  debug(`fileExists called with: ${JSON.stringify(arguments)}`);
  try {
    await fs.statAsync(f);
    return f;
  } catch (e) {
    throw e;
  }
}
1348868
function(filepath) {
        return grunt.file.exists(filepath) ?
          Math.floor(fs.statSync(filepath).mtime.getTime() / 1000) : 0;
        // mtime before epochtime isn't supported.
      }
1336859
function check(filename) {
  this.filename = filename && path.resolve(filename) || '';
  this.types = [];
  this.valid = null;
}
660538
function isJavaScriptFile(filepath) {
  if (!fs.statSync(filepath).isFile()) {
    return false;
  }
  if (path.basename(filepath) === 'index.js') {
    return false;
  }
  return filepath.slice(-3) === '.js';
}
750396
function(path) {
        // TODO: Does file exist at the file location path? If so, do something about it...
        //var defaultManager = $.NSFileManager('alloc')('init')
        //if (defaultManager('fileExistsAtPath',NSlocation)) {
        //    console.log("File already exists!")
        //}

        if (!path){
            // Default Destination: e.g. "/Users/hugs/Desktop/Castro_uul3di.mov"
            var homeDir =  $.NSHomeDirectory();
            var desktopDir = homeDir.toString() + '/Desktop/';
            var randomString = (Math.random() + 1).toString(36).substring(12);
            var filename = 'Castro_' + randomString + '.mp4';
            this.location = desktopDir + filename;
        } else {
            // TODO: Make sure path is legit.
            this.location = path;
        }
        this.NSlocation = $.NSString('stringWithUTF8String', this.location);
        this.NSlocationURL = $.NSURL('fileURLWithPath', this.NSlocation);
    }