|
1 | | -program example_path |
2 | | - use stdlib_system, only: joinpath, operator(/), splitpath, ISWIN, dirname, basename |
3 | | - character(len=:), allocatable :: p1, p2, head, tail |
| 1 | +! Usage of joinpath, operator(/) |
| 2 | +program example_join |
| 3 | + use stdlib_system, only: joinpath, operator(/) |
| 4 | + character(len=:), allocatable :: p1, p2, p3 |
4 | 5 | character(len=20) :: parr(4) |
5 | 6 |
|
6 | | - if (ISWIN) then |
7 | | - p1 = 'C:'/'Users'/'User1'/'Desktop' |
8 | | - parr = [character(len=20) :: 'C:', 'Users', 'User1', 'Desktop'] |
9 | | - p2 = joinpath(parr) |
| 7 | + p1 = ''/'home'/'User1'/'Desktop' |
| 8 | + p2 = joinpath('/home/User1', 'Desktop') |
10 | 9 |
|
11 | | - ! p1 == p2 = 'C:\Users\User1\Desktop' |
12 | | - print *, p1 |
13 | | - print *, "p1 == p2: ", p1 == p2 |
| 10 | + parr = [character(len=20) :: '', 'home', 'User1', 'Desktop'] |
| 11 | + p3 = joinpath(parr) |
14 | 12 |
|
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 |
| 13 | + ! (p1 == p2 == p3) = '/home/User1/Desktop' |
| 14 | + print *, p1 ! /home/User1/Desktop |
| 15 | + print *, "p1 == p2: ", p1 == p2 ! T |
| 16 | + print *, "p2 == p3: ", p2 == p3 ! T |
| 17 | +end program example_join |
0 commit comments