This language bar is your friend. Select your favorite languages!
Select your favorite languages :
  • Or search :

Idiom #144 Check if file exists

Set boolean b to true if file at path fp exists on filesystem; false otherwise.

Beware that you should never do this and then in the next instruction assume the result is still valid, this is a race condition on any multitasking OS.

#include <unistd.h>
#include <stdbool.h>
bool b = (access(_fp, F_OK) == 0) ? true : false;
(require '[clojure.java.io :as io])
(let [b (.exists (io/file fp))]
#include <filesystem>
bool b = std::filesystem::exists(fp);
bool b = File.Exists(fp);
import std.file;
bool b = fp.exists;
  inquire (file=fp,exist=b)
import "os"
_, err := os.Stat(fp)
b := !os.IsNotExist(err)
import System.Directory
b = doesFileExist fp
const fs = require('fs');
const b = fs.existsSync(fp);
import java.io.File;
boolean b = new File(fb).exists();
$b = file_exists($fp);
uses sysutils;
b := FileExists(fp);
my $b = -f $fp;
from pathlib import Path
b = Path(fp).exists()
import os
b = os.path.exists(fp)
b = File.exist?(fp)
let b = std::path::Path::new(fp).exists();

New implementation...