sys_remove_dir Subroutine

public subroutine sys_remove_dir(dirpath, success)

Remove a directory and all its contents

Arguments

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

Source Code

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

        if (get_os_type() == OS_WINDOWS) then
            command = 'rmdir /s /q "'//trim(escape_shell_arg(dirpath))//'" 2>nul'
        else
            command = 'rm -rf "'//trim(escape_shell_arg(dirpath))//'" 2>/dev/null'
        end if

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