is_dir Function

public function is_dir(dir)

test if a name matches an existing directory path

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: dir

Return Value logical


Source Code

logical function is_dir(dir)
    character(*), intent(in) :: dir
    integer :: stat

    is_dir = .false.
    if (len_trim(dir) == 0) return
    select case (get_os_type())

    case (OS_UNKNOWN, OS_LINUX, OS_MACOS, OS_CYGWIN, OS_SOLARIS, OS_FREEBSD, OS_OPENBSD)
#ifndef FPM_BOOTSTRAP
        is_dir = c_is_dir(dir(1:len_trim(dir))//c_null_char) /= 0
        return
#else
        call run( "test -d " // quote(trim(dir)) , &
                & exitstat=stat,echo=.false.,verbose=.false.)
#endif

    case (OS_WINDOWS)
        call run('cmd /d /c if not exist "' // windows_path(trim(dir)) // '\" exit /B 1', &
                & exitstat=stat,echo=.false.,verbose=.false.)

    end select

    is_dir = (stat == 0)

end function is_dir