Check if a file exists (handles both regular files and symlinks)
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | filepath |
function sys_file_exists(filepath) result(exists) character(len=*), intent(in) :: filepath logical :: exists integer :: unit, iostat ! First try standard inquire inquire (file=filepath, exist=exists) ! If not found, try opening it (handles symlinks better) if (.not. exists) then open (newunit=unit, file=filepath, status='old', action='read', iostat=iostat) if (iostat == 0) then exists = .true. close (unit) else exists = .false. end if end if end function sys_file_exists