diff options
author | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-12 20:54:33 -0400 |
---|---|---|
committer | Jeffrey Armstrong <jeff@approximatrix.com> | 2021-04-12 20:54:33 -0400 |
commit | a001a16dbb64590172677092e2a55b594c6a2f7b (patch) | |
tree | a295e612d629b60aa31b5c22133e5e1da075f6df | |
parent | 2aeb2f1276e009badab7d0a847f4d7e93e2cd0cd (diff) | |
download | levitating-a001a16dbb64590172677092e2a55b594c6a2f7b.tar.gz levitating-a001a16dbb64590172677092e2a55b594c6a2f7b.zip |
Added directory listing feature to utilities in preparation for building releases page.
-rw-r--r-- | common/utilities.F90 | 102 |
1 files changed, 102 insertions, 0 deletions
diff --git a/common/utilities.F90 b/common/utilities.F90 index cc2f727..961a349 100644 --- a/common/utilities.F90 +++ b/common/utilities.F90 @@ -272,4 +272,106 @@ contains end subroutine replace_field_int + function get_directories_in_directory(directory) result(res) + implicit none + + character(*), intent(in)::directory + character(1024), dimension(:), pointer::res + character(80)::line + character(len=:), pointer::tempfile + integer::dcount, unum, ierr, i + + tempfile => generate_temporary_filename() + res => null() + + call execute_command_line("ls -l "//trim(directory)//" > "//trim(tempfile), & + wait=.true.) + + open(newunit=unum, file=tempfile, action='read') + dcount = 0 + read(unum, '(A)', iostat=ierr) line + do while(ierr == 0) + if(line(1:1) == 'd') then + dcount = dcount + 1 + end if + read(unum, '(A)', iostat=ierr) line + end do + + close(unum) + + if(dcount > 0) then + allocate(res(dcount)) + + ! Now call ls, but group directories first + call execute_command_line("ls -g "//trim(directory)//" > "//trim(tempfile), & + wait=.true.) + open(newunit=unum, file=tempfile, action='read') + i = 0 + read(unum, '(A)', iostat=ierr) line + do while(ierr == 0 .and. i < dcount) + i = i + 1 + call combine_paths(trim(directory), trim(line), res(i)) + read(unum, '(A)', iostat=ierr) line + end do + + close(unum) + end if + + call unlink(tempfile) + + end function get_directories_in_directory + + function get_files_in_directory(directory) result(res) + implicit none + + character(*), intent(in)::directory + character(1024), dimension(:), pointer::res + character(80)::line + character(len=:), pointer::tempfile + integer::dcount, total_count, unum, ierr, i + + tempfile => generate_temporary_filename() + res => null() + + call execute_command_line("ls -l "//trim(directory)//" > "//trim(tempfile), & + wait=.true.) + + open(newunit=unum, file=tempfile, action='read') + dcount = 0 + total_count = 0 + read(unum, '(A)', iostat=ierr) line + do while(ierr == 0) + if(line(1:1) == 'd') then + dcount = dcount + 1 + end if + total_count = total_count + 1 + read(unum, '(A)', iostat=ierr) line + end do + + close(unum) + + if((total_count - dcount) > 0) then + allocate(res(total_count - dcount)) + + ! Now call ls, but group directories first + call execute_command_line("ls -g "//trim(directory)//" > "//trim(tempfile), & + wait=.true.) + open(newunit=unum, file=tempfile, action='read') + + read(unum, '(A)', iostat=ierr) line + do while(ierr == 0 .and. i < dcount) + i = i + 1 + if(i > dcount) then + call combine_paths(trim(directory), trim(line), res(i-dcount)) + end if + read(unum, '(A)', iostat=ierr) line + end do + + close(unum) + end if + + call unlink(tempfile) + + end function get_files_in_directory + end module utilities
\ No newline at end of file |