system_readdir(3f) - [M_system:QUERY_FILE] read a directory using readdir(3c) (LICENSE:PD)
Synopsis
Description
Options
Returns
Examples
Author
License
subroutine system_readdir(dir,filename,ierr)
type(c_ptr),value :: dir character(len=:),intent(out),allocatable :: filename integer,intent(out) :: ierr
system_readdir(3f) returns the name of the directory entry at the current position in the directory stream specified by the argument DIR, and positions the directory stream at the next entry. It returns a null name upon reaching the end of the directory stream.
DIR A pointer to the directory opened by system_opendir(3f).
FILENAME the name of the directory entry at the current position in the directory stream specified by the argument DIR, and positions the directory stream at the next entry. The readdir() function does not return directory entries containing empty names. If entries for dot or dot-dot exist, one entry is returned for dot and one entry is returned for dot-dot.
The entry is marked for update of the last data access timestamp each time it is read.
reaching the end of the directory stream, the name is a blank name.
IERR If IERR is set to non-zero on return, an error occurred.
Sample program:
program demo_system_readdir use M_system, only : system_opendir,system_readdir use M_system, only : system_rewinddir,system_closedir use iso_c_binding implicit nonetype(c_ptr) :: dir character(len=:),allocatable :: filename integer :: i, ierr !--- open directory stream to read from call system_opendir(.,dir,ierr) if(ierr.eq.0)then !--- read directory stream twice do i=1,2 write(*,(a,i0))PASS ,i do call system_readdir(dir,filename,ierr) if(filename.eq. )exit write(*,*)filename enddo call system_rewinddir(dir) enddo endif !--- close directory stream call system_closedir(dir,ierr)
end program demo_system_readdir
John S. Urban
Public Domain
Nemo Release 3.1 | system_readdir (3m_system) | March 07, 2025 |