Skip to content

Commit be3d5b5

Browse files
committed
added example
1 parent 04b1bed commit be3d5b5

File tree

2 files changed

+30
-0
lines changed

2 files changed

+30
-0
lines changed

example/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ ADD_EXAMPLE(path_join)
1616
ADD_EXAMPLE(path_split_path)
1717
ADD_EXAMPLE(path_base_name)
1818
ADD_EXAMPLE(path_dir_name)
19+
ADD_EXAMPLE(path_abs)
1920
ADD_EXAMPLE(make_directory)
2021
ADD_EXAMPLE(remove_directory)
2122
ADD_EXAMPLE(cwd)

example/system/example_path_abs.f90

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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+

0 commit comments

Comments
 (0)