Checks if a directory exists and/or if we have write permission in that directory.
Returns .true. if directory exists and is accessible
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
character(len=*), | intent(in) | :: | path |
Directory path |
function check_dir_exist(path) result(exists) !! Checks if a directory exists and/or if we have write permission !! in that directory. !! !! Returns .true. if directory exists and is accessible character(len=*), intent(in) :: path !! Directory path logical:: exists ! Local variables integer :: u, ios, len_trimmed ! Get length of directory path len_trimmed = len_trim(path) ! Attempt to open a temporary file in the specified directory if (path(len_trimmed:len_trimmed) == "/") then open(newunit=u, file=trim(path)//"tmp", status="new", iostat=ios) else open(newunit=u, file=trim(path)//"/tmp", status="new", iostat=ios) end if if (ios /= 0) then exists = .false. else ! If succesfull, delete the temporary file close(unit=u, status="delete") exists = .true. end if end function check_dir_exist