@@ -953,18 +953,19 @@ subroutine make_directory_all(path, err)
953
953
character (len=* ), intent (in ) :: path
954
954
type (state_type), optional , intent (out ) :: err
955
955
956
- integer :: code, i, indx
956
+ integer :: i, indx
957
957
type (state_type) :: err0
958
958
character (len= 1 ) :: sep
959
- logical :: is_dir
959
+ logical :: is_dir, check_is_dir
960
960
961
961
sep = path_sep()
962
962
i = 1
963
963
indx = find(path, sep, i)
964
+ check_is_dir = .true.
964
965
965
966
do
966
967
! Base case to exit the loop
967
- if (indx == 0 .or. indx == len ( trim (path)) ) then
968
+ if (indx == 0 ) then
968
969
is_dir = is_directory(path)
969
970
970
971
if (.not. is_dir) then
@@ -975,12 +976,19 @@ subroutine make_directory_all(path, err)
975
976
end if
976
977
977
978
return
979
+ else
980
+ exit
978
981
end if
979
982
end if
980
983
981
- is_dir = is_directory(path(1 :indx))
984
+ if (check_is_dir) then
985
+ is_dir = is_directory(path(1 :indx))
986
+ end if
982
987
983
988
if (.not. is_dir) then
989
+ ! no need for further `is_dir` checks
990
+ ! all paths going forward need to be created
991
+ check_is_dir = .false.
984
992
call make_directory(path(1 :indx), err0)
985
993
986
994
if (err0% error()) then
@@ -989,7 +997,7 @@ subroutine make_directory_all(path, err)
989
997
end if
990
998
end if
991
999
992
- i = i + 1
1000
+ i = i + 1 ! the next occurence of `sep`
993
1001
indx = find(path, sep, i)
994
1002
end do
995
1003
end subroutine make_directory_all
0 commit comments