C Library Functions  - system_isreg (3)

NAME

system_isreg(3f) - [M_system:QUERY_FILE] 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=:),allocatable :: filenames(:)
   logical,allocatable :: mymask(:)
   integer                         :: i
   ! list readable non-hidden regular files and links in current directory
        ! make list of all files in current directory
        filenames=system_dir(pattern=’*’)
        ! select regular files and links
        mymask= isreg(filenames).or.islnk(filenames)
        ! skip hidden directories in those
        where(mymask) mymask=filenames(:)(1:1).ne.’.’
        ! select readable files in those
        where(mymask) mymask=access(filenames,R_OK)
        filenames=pack(filenames,mask=mymask)
        write(*,’(a)’)(trim(filenames(i)),i=1,size(filenames))
   end program demo_system_isreg


Nemo Release 3.1 system_isreg (3) July 22, 2023
Generated by manServer 1.08 from 4ec21ccf-fb4a-4b45-9feb-06e45a5bd1c4 using man macros.