Remove one named file; a missing file counts as success. unlink never removes a directory.
| Type | Intent | Optional | Attributes | Name | ||
|---|---|---|---|---|---|---|
| character(len=*), | intent(in) | :: | path | |||
| integer, | intent(out) | :: | status |
subroutine remove_file_if_exists(path, status) character(len=*), intent(in) :: path integer, intent(out) :: status character(kind=c_char), allocatable :: c_path(:) logical :: exists if (len_trim(path) == 0) then status = filesystem_empty_path return end if inquire (file=trim(path), exist=exists) status = filesystem_success if (.not. exists) return call to_c_string(trim(path), c_path) if (c_unlink(c_path) /= 0_c_int) status = filesystem_os_error end subroutine remove_file_if_exists