Skip to content

Commit 572ad46

Browse files
committed
example
1 parent f41dee4 commit 572ad46

File tree

2 files changed

+42
-0
lines changed

2 files changed

+42
-0
lines changed

example/system/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ ADD_EXAMPLE(process_5)
1111
ADD_EXAMPLE(process_6)
1212
ADD_EXAMPLE(process_7)
1313
ADD_EXAMPLE(sleep)
14+
ADD_EXAMPLE(path_1)

example/system/example_path_1.f90

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
program example_path
2+
use stdlib_system, only: joinpath, operator(/), splitpath, ISWIN, dirname, basename
3+
character(len=:), allocatable :: p1, p2, head, tail
4+
character(len=20) :: parr(4)
5+
6+
if (ISWIN) then
7+
p1 = 'C:'/'Users'/'User1'/'Desktop'
8+
parr = [character(len=20) :: 'C:', 'Users', 'User1', 'Desktop']
9+
p2 = joinpath(parr)
10+
11+
! p1 == p2 = 'C:\Users\User1\Desktop'
12+
print *, p1
13+
print *, "p1 == p2: ", p1 == p2
14+
15+
call splitpath(p1, head, tail)
16+
print *, p1 // " -> " // head // " + " // tail
17+
18+
call splitpath(head, p1, tail)
19+
print *, head // " -> " // p1 // " + " // tail
20+
21+
print *, 'dirname of '// p1 // ' -> ' // dirname(p1)
22+
print *, 'basename of '// p1 // ' -> ' // basename(p1)
23+
else
24+
p1 = ''/'home'/'User1'/'Desktop'
25+
parr = [character(len=20) :: '', 'home', 'User1', 'Desktop']
26+
p2 = joinpath(parr)
27+
28+
! p1 == p2 = '/home/User1/Desktop'
29+
print *, p1
30+
print *, "p1 == p2: ", p1 == p2
31+
32+
call splitpath(p1, head, tail)
33+
print *, p1 // " -> " // head // " + " // tail
34+
35+
call splitpath(head, p1, tail)
36+
print *, head // " -> " // p1 // " + " // tail
37+
38+
print *, 'dirname of '// p1 // ' -> ' // dirname(p1)
39+
print *, 'basename of '// p1 // ' -> ' // basename(p1)
40+
end if
41+
end program example_path

0 commit comments

Comments
 (0)