How to check if a file exists in fortran 90 ?

Published: April 02, 2018

DMCA.com Protection Status

To check if a file exists in fortran 90, there is a fortran function called INQUIRE. Example of a fortran code (called here "test.f90"):

program test

logical :: file_exists

INQUIRE(FILE="inputs.txt", EXIST=file_exists)

write(6,*) file_exists

end

Compilation

gfortran test.f90 -o test
test

will return:

F if the file inputs.txt does not exist
T if the file inputs.txt exists

References