sys_create_dir Subroutine

public subroutine sys_create_dir(dirpath, success, create_parents)

Create a directory (with parent directories if needed)

Arguments

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

Source Code

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

        with_parents = .true.
        if (present(create_parents)) with_parents = create_parents

        if (get_os_type() == OS_WINDOWS) then
            if (with_parents) then
                command = 'mkdir "'//trim(escape_shell_arg(dirpath))//'" 2>nul'
            else
                command = 'mkdir "'//trim(escape_shell_arg(dirpath))//'" 2>nul'
            end if
        else
            if (with_parents) then
                command = 'mkdir -p "'//trim(escape_shell_arg(dirpath))//'" 2>/dev/null'
            else
                command = 'mkdir "'//trim(escape_shell_arg(dirpath))//'" 2>/dev/null'
            end if
        end if

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