|
| 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