sys_remove_file Subroutine

public subroutine sys_remove_file(filepath, success)

Remove a file

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: filepath
logical, intent(out), optional :: success

Source Code

    subroutine sys_remove_file(filepath, success)
        character(len=*), intent(in) :: filepath
        logical, intent(out), optional :: success
        character(len=512) :: command
        integer :: exitstat

        if (get_os_type() == OS_WINDOWS) then
            command = 'del /f /q "'//trim(escape_shell_arg(filepath))//'" 2>nul'
        else
            command = 'rm -f "'//trim(escape_shell_arg(filepath))//'" 2>/dev/null'
        end if

        call execute_command_line(command, exitstat=exitstat)
        if (present(success)) success = (exitstat == 0)
    end subroutine sys_remove_file