File tree Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Expand file tree Collapse file tree 2 files changed +30
-0
lines changed Original file line number Diff line number Diff line change @@ -16,6 +16,7 @@ ADD_EXAMPLE(path_join)
16
16
ADD_EXAMPLE (path_split_path )
17
17
ADD_EXAMPLE (path_base_name )
18
18
ADD_EXAMPLE (path_dir_name )
19
+ ADD_EXAMPLE (path_abs )
19
20
ADD_EXAMPLE (make_directory )
20
21
ADD_EXAMPLE (remove_directory )
21
22
ADD_EXAMPLE (cwd )
Original file line number Diff line number Diff line change
1
+ ! Illustrate the usage of `abs_path`, `is_abs`
2
+ program example_path_abs
3
+ use stdlib_system, only: abs_path, is_abs
4
+ use stdlib_error, only: state_type
5
+ implicit none
6
+
7
+ character (* ), parameter :: path = " path/to/check"
8
+ character (:), allocatable :: absolute_path
9
+ type (state_type) :: err
10
+
11
+ if (is_abs(path)) then
12
+ print * , " Path is absolute!"
13
+ ! terminate the program since path is already absolute
14
+ stop
15
+ else
16
+ print * , " Path is not absolute!"
17
+ end if
18
+
19
+ ! get the absolute path
20
+ absolute_path = abs_path(path, err)
21
+
22
+ if (err% error()) then
23
+ ! there was an error! print it
24
+ print * , " error converting to absolute path: " // err% print ()
25
+ else
26
+ print * , " absolute path => " // absolute_path
27
+ end if
28
+ end program example_path_abs
29
+
You can’t perform that action at this time.
0 commit comments