Logo

Programming-Idioms

This language bar is your friend. Select your favorite languages!
  • Ada

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 not do this and then in the next instruction assume the result is still valid, this is a race condition on any multitasking OS.

with Ada.Directories;
B : constant Boolean := Ada.Directories.Exists (FP);
#include <unistd.h>
#include <stdbool.h>
bool b = access(_fp, F_OK) == 0

New implementation...
< >
programming-idioms.org