check if a file or directory exists

@return FTPCLient
@throws PageException
@throws IOException
337194
private AFTPClient actionExists() throws PageException, IOException {
	required("item", item);

	AFTPClient client = getClient();
	FTPFile file = existsFile(client, item, false);
	Struct cfftp = writeCfftp(client);

	cfftp.setEL(RETURN_VALUE, Caster.toBoolean(file != null));
	cfftp.setEL(SUCCEEDED, Boolean.TRUE);

	return client;
    }
581033
private FileStatus[] listStatus(FTPClient client, Path file)
      throws IOException {
    Path workDir = new Path(client.printWorkingDirectory());
    Path absolute = makeAbsolute(workDir, file);
    FileStatus fileStat = getFileStatus(client, absolute);
    if (!fileStat.isDir()) {
      return new FileStatus[] { fileStat };
    }
    FTPFile[] ftpFiles = client.listFiles(absolute.toUri().getPath());
    FileStatus[] fileStats = new FileStatus[ftpFiles.length];
    for (int i = 0; i < ftpFiles.length; i++) {
      fileStats[i] = getFileStatus(ftpFiles[i], absolute);
    }
    return fileStats;
  }
198461
private AFTPClient actionChangeDir() throws IOException, PageException {
	required("directory", directory);

	AFTPClient client = getClient();
	client.changeWorkingDirectory(directory);
	writeCfftp(client);
	return client;
    }
1128416
public static function exists(string $path) : bool
    {
        try {
            return ErrorCatcher::run(static function() use ($path) {
                return file_exists($path);
            });
        } catch (\ErrorException $e) {
            throw new IoException('Error checking if ' . $path . ' exists', 0, $e);
        }
    }
56644
public function exists($pageName)
    {
        $ds = DIRECTORY_SEPARATOR;
        $path = app_path().$ds.'lablog'.$ds.$pageName.'.page';

        if ($this->fs->exists($path)) {
            return true;
        }

        return false;
    }
1327333
def exists(self, filepath):
        """"""
        if self.is_ssh(filepath):
            self._check_ftp()
            remotepath = self._get_remote(filepath)
            try:
                self.ftp.stat(remotepath)
            except IOError as e:
                if e.errno == errno.ENOENT:
                    return False
            else:
                return True
        else:
            return os.path.exists(filepath)
103919
public function file_exists($contextid, $component, $filearea, $itemid, $filepath, $filename) {
        $filepath = clean_param($filepath, PARAM_PATH);
        $filename = clean_param($filename, PARAM_FILE);

        if ($filename === '') {
            $filename = '.';
        }

        $pathnamehash = $this->get_pathname_hash($contextid, $component, $filearea, $itemid, $filepath, $filename);
        return $this->file_exists_by_hash($pathnamehash);
    }
929507
protected function pageExists($file)
    {
        $file = str_replace(DIRECTORY_SEPARATOR, '/', $file);
        return $file != ''
            && substr($file, 0, strlen($this->pages_dir)) == $this->pages_dir
            && file_exists($file)
            && is_readable($file);
    }
1054159
private FileStatus getFileStatus(FTPClient client, Path file)
      throws IOException {
    FileStatus fileStat = null;
    Path workDir = new Path(client.printWorkingDirectory());
    Path absolute = makeAbsolute(workDir, file);
    Path parentPath = absolute.getParent();
    if (parentPath == null) { // root dir
      long length = -1; // Length of root dir on server not known
      boolean isDir = true;
      int blockReplication = 1;
      long blockSize = DEFAULT_BLOCK_SIZE; // Block Size not known.
      long modTime = -1; // Modification time of root dir not known.
      Path root = new Path("/");
      return new FileStatus(length, isDir, blockReplication, blockSize,
          modTime, root.makeQualified(this));
    }
    String pathName = parentPath.toUri().getPath();
    FTPFile[] ftpFiles = client.listFiles(pathName);
    if (ftpFiles != null) {
      for (FTPFile ftpFile : ftpFiles) {
        if (ftpFile.getName().equals(file.getName())) { // file found in dir
          fileStat = getFileStatus(ftpFile, parentPath);
          break;
        }
      }
      if (fileStat == null) {
        throw new FileNotFoundException("File " + file + " does not exist.");
      }
    } else {
      throw new FileNotFoundException("File " + file + " does not exist.");
    }
    return fileStat;
  }
1083867
public function existsFile() {
		$file =$this->getPath();
		if (file_exists($file)) {
			if ($this->type == self::TYPE_ENTITY) {
				return self::FILE_MATCH;
			}
			
			$data = file_get_contents($file);
			if (strpos($data, "@version ".Version::BUILDER_VERSION) !== FALSE) {
				return self::FILE_MATCH;
			} else {
				return self::FILE_OUTDATED;
			}
		}
		return self::FILE_MISSING;
	}
775599
private AFTPClient actionListDir() throws PageException, IOException {
	required("name", name);
	required("directory", directory);

	AFTPClient client = getClient();
	FTPFile[] files = client.listFiles(directory);
	if (files == null) files = new FTPFile[0];

	pageContext.setVariable(name, toQuery(files, "ftp", directory, client.getRemoteAddress().getHostName()));
	writeCfftp(client);
	return client;
    }
306239
public function checkForCacheFile()
    {
        // first check if we can create a file
        if (!$this->canCreateCacheFile()) {
            return;
        }
        $cacheEntry = HtmlCacheCache::findOne(['uri' => $this->uri, 'siteId' => $this->siteId]);

        // check if cache exists
        if ($cacheEntry) {
            $file = $this->getCacheFileName($cacheEntry->uid);
            if (file_exists($file)) {
                // load cache - may return false if cache has expired
                if ($this->loadCache($file)) {
                    return \Craft::$app->end();
                }
            }
        }
        // Turn output buffering on
        ob_start();
    }
633101
@Override
    public PageException execute(String id) {
	SpoolerTask task = getTaskById(openDirectory, id);
	if (task == null) task = getTaskById(closedDirectory, id);
	if (task != null) {
	    return execute(task);
	}
	return null;
    }
698452
protected function doesExist()
    {
        if (!file_exists($this->path)) {
            throw new LocationDoesExist(
                $this->getPath() .' does not exist!',
                self::WRITABLE_DOES_NOT_EXIST_ERROR
            );
        }
        return true;
    }
1016703
public boolean exists() {
		try {
			read();
			return true;
		} catch (FileFormatException e) {
			return false;
		} catch (IOException e) {
			logger.error(e);
			return false;
		}
	}
68887
public function exists($files)
    {
        $maxPathLength = PHP_MAXPATHLEN - 2;

        foreach ($this->toIterable($files) as $file) {
            if (strlen($file) > $maxPathLength) {
                throw new IOException(sprintf('Could not check if file exist because path length exceeds %d characters.', $maxPathLength), 0, null, $file);
            }

            if (!file_exists($file)) {
                return false;
            }
        }

        return true;
    }
500923
private FTPClient connect() throws IOException {
    FTPClient client = null;
    Configuration conf = getConf();
    String host = conf.get("fs.ftp.host");
    int port = conf.getInt("fs.ftp.host.port", FTP.DEFAULT_PORT);
    String user = conf.get("fs.ftp.user." + host);
    String password = conf.get("fs.ftp.password." + host);
    client = new FTPClient();
    client.connect(host, port);
    int reply = client.getReplyCode();
    if (!FTPReply.isPositiveCompletion(reply)) {
      throw new IOException("Server - " + host
          + " refused connection on port - " + port);
    } else if (client.login(user, password)) {
      client.setFileTransferMode(FTP.BLOCK_TRANSFER_MODE);
      client.setFileType(FTP.BINARY_FILE_TYPE);
      client.setBufferSize(DEFAULT_BUFFER_SIZE);
    } else {
      throw new IOException("Login failed on server - " + host + ", port - "
          + port);
    }

    return client;
  }