[UP]


Manual Reference Pages  - system_isreg (3)

NAME

system_isreg(3f) - [M_system] checks if argument is a regular file (LICENSE:PD)

CONTENTS

Synopsis
Description
Options
Return Value
Errors
See Also
Example

SYNOPSIS

elemental impure logical function system_isreg(pathname)

character(len=*),intent(in) :: pathname logical :: system_isreg

DESCRIPTION

The isreg(3f) function checks if path is a regular file

OPTIONS

path a character string representing a pathname. Trailing spaces are ignored.

RETURN VALUE

The system_isreg() function should always be successful and no return value is reserved to indicate an error.

ERRORS

No errors are defined.

SEE ALSO

system_islnk(3f), system_stat(3f), system_isdir(3f), system_perm(3f)

EXAMPLE

check if filename is a regular file

   program simple
   use M_system, only : system_isreg
   implicit none
   integer                     :: i
   character(len=80),parameter :: names(*)=[ &
   ’/tmp            ’, &
   ’test.txt        ’, &
   ’~/.bashrc       ’, &
   ’.bashrc         ’, &
   ’.               ’]
   do i=1,size(names)
      write(*,*)’ is ’,trim(names(i)),’ a regular file? ’, system_isreg(names(i))
   enddo
   end program simple

    EXTENDED EXAMPLE

list readable non-hidden regular files and links in current directory

   program demo_system_isreg
   use M_system, only : isreg=>system_isreg, islnk=>system_islnk
   use M_system, only : access=>system_access, R_OK
   use M_system, only : system_dir
   implicit none
   character(len=1024),allocatable :: filenames(:) ! BUG: cannot use len=: in gfortran 8.3.1
   logical,allocatable :: mymask(:)
   integer                         :: i
        ! list readable non-hidden regular files and links in current directory
        filenames=system_dir(pattern=’*’)                ! make list of all files in current directory
        mymask= isreg(filenames).or.islnk(filenames)   ! select regular files and links
        where(mymask) mymask=filenames(:)(1:1).ne.’.’  ! skip hidden directories in those
        where(mymask) mymask=access(filenames,R_OK)    ! select readable files in those
        filenames=pack(filenames,mask=mymask)
        write(*,’(a)’)(trim(filenames(i)),i=1,size(filenames))
   end program demo_system_isreg


system_isreg (3) July 05, 2020
Generated by manServer 1.08 from 054073b4-b730-4c1d-ad0b-c806cd78c6db using man macros.