Skip to content

Instantly share code, notes, and snippets.

@natebenes
Created May 3, 2010 00:39
Show Gist options
  • Save natebenes/387596 to your computer and use it in GitHub Desktop.
Save natebenes/387596 to your computer and use it in GitHub Desktop.
program testNames
implicit none
integer :: count
character(len=50), dimension(500000) :: AllNames
CALL getFileNames(AllNames, count)
WRITE(*,*) count
end program
subroutine getFileNames(names, counter)
implicit none
integer, intent(out) :: counter
character(len=50), dimension(500000), INTENT(OUT) :: names
character(len=50) :: tempStr = "", pwd=""
integer :: openErr, readErr, strLen
counter = 0
call system("ls -R > lsAll.out")
open(file="lsAll.out", unit=55, action="read", iostat=openErr)
do
read(55,"(A)",iostat=readErr) tempStr
if(readErr /= 0) then
if(counter<10) WRITE(*,*) "can't open"
exit
end if
if(tempStr(1:2) == "./") then ! its a dir
pwd = TRIM(tempStr)
else
counter = counter + 1
if(len_trim(trim(pwd)//trim(tempStr))<51) then
names(counter) = (trim(pwd))//(trim(tempStr))
write(*,*) trim(trim(pwd))//(trim(tempStr))
end if
end if
end do
close(unit=55)
call system("rm lsAll.out")
end subroutine
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment