Skip to content

Commit d8fedab

Browse files
committed
add example
1 parent 988127f commit d8fedab

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

example/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,4 @@ ADD_EXAMPLE(process_7)
1313
ADD_EXAMPLE(sleep)
1414
ADD_EXAMPLE(make_directory)
1515
ADD_EXAMPLE(remove_directory)
16+
ADD_EXAMPLE(cwd)

example/system/example_cwd.f90

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
! Illustrate the usage of get_cwd, set_cwd
2+
program example_cwd
3+
use stdlib_system, only: get_cwd, set_cwd
4+
use stdlib_error, only: state_type
5+
implicit none
6+
7+
character(len=:), allocatable :: path
8+
type(state_type) :: err
9+
10+
call get_cwd(path, err)
11+
12+
if (err%error()) then
13+
print *, "Error getting current working directory: "//err%print()
14+
end if
15+
16+
print *, "CWD: "//path
17+
18+
call set_cwd("./src", err)
19+
20+
if (err%error()) then
21+
print *, "Error setting current working directory: "//err%print()
22+
end if
23+
24+
call get_cwd(path, err)
25+
26+
if (err%error()) then
27+
print *, "Error getting current working directory after using set_cwd: "//err%print()
28+
return
29+
end if
30+
31+
print *, "CWD: "//path
32+
end program example_cwd
33+

0 commit comments

Comments
 (0)