File: example_exists.f90

package info (click to toggle)
fortran-stdlib 0.8.1-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 34,008 kB
  • sloc: f90: 24,178; ansic: 1,244; cpp: 623; python: 119; makefile: 13
file content (30 lines) | stat: -rw-r--r-- 852 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
! Illustrate the usage of `exists`
program example_exists
    use stdlib_system, only: exists, fs_type_unknown, fs_type_regular_file, &
        fs_type_directory, fs_type_symlink
    use stdlib_error, only: state_type
    implicit none

    type(state_type) :: err

    ! Path to check
    character(*), parameter :: path = "path/to/check"
    ! To get the type of the path
    integer :: t

    t = exists(path, err)

    if (err%error()) then
        ! An error occured, print it
        print *, err%print()
    end if

    ! switching on the type returned by `exists`
    select case (t)
    case (fs_type_unknown); print *, "Unknown type!"
    case (fs_type_regular_file); print *, "Regular File!"
    case (fs_type_directory); print *, "Directory!"
    case (fs_type_symlink); print *, "Symbolic Link!"
    end select
end program example_exists