pxfdirectory

Date:

10-20-2011

NAME

PXFOPENDIR, PXFREADDIR, PXFREWINDDIR, PXFCLOSEDIR - Performs directory operations

SYNOPSIS

CHARACTER*n dirname
INTEGER lendirname, iopendir, ierror
CALL PXFOPENDIR(dirname, lendirname, iopendirid, ierror)

INTEGER idirid, jdirent, ierror
CALL PXFREADDIR(idirid, jdirent, ierror)

INTEGER idirid, ierror
CALL PXFREWINDDIR(idirid, ierror)

INTEGER idirid, ierror
CALL PXFCLOSEDIR(idirid, ierror)

IMPLEMENTATION

Cray Linux Environment (CLE)

STANDARDS

IEEE Std 1003.9-1992 standard interface for FORTRAN 77

DESCRIPTION

The PXFOPENDIR subroutine uses the opendir routine to open a directory stream for the directory dirname and positions the stream at the first directory entry.

The PXFREADDIR subroutine uses the readdir function to read a directory stream for the next entry in the directory stream.

The PXFREWINDDIR subroutine uses the rewinddir function to reset the position in the directory stream to the first entry of a directory stream while updating the directory stream to the current state of the directory, as a call to PXFOPENDIR would do.

The PXFCLOSEDIR subroutine uses the closedir function to close the directory stream referenced by idirid. Upon sucessful completion, idirid is undefined and the result of subsequent calls to PXFCLOSEDIR with idirid is not well defined.

All arguments must be of default kind unless documented otherwise. Default kind is KIND=4 for integer, real, complex, and logical arguments

The following is a list of valid arguments for these subroutines:

dirname

An input character array variable containing the path for the directory to be opened.

lendirname

An input integer variable containing the length of dirname.

iopendirid

An output integer variable for the unique directory ID.

  • The iopendirid argument becomes the unique directory ID (idirid) that is used by PXFREADDIR, PXFREWINDDIR, and PXFCLOSEDIR

ierror

An output integer variable that contains zero if the operation was successful or nonzero if the operation was not successful.

idirid

An input integer variable for the unique directory ID generated by PXFOPENDIR.

jdirent

An output structure handle created by PXFSTRUCTCREATE(3F) that contains one directory entry.

Besides the errors returned by opendir, PXFOPENDIR may return the following error values:

EINVAL

If lendirname < 0 or lendirname > LEN(dirname).

ENOMEM

If memory needed by PXFOPENDIR could not be allocated.

EXAMPLES

In this example, the /dev/dsk directory is opened, the directory entries are read and printed, the directory is rewound and the contents are redisplayed, and then the directory is closed.

program pxftest
integer ierror
integer (KIND=8) jdirent,idirid

CALL PXFSTRUCTCREATE('dirent',jdirent,ierror)
CALL PXFOPENDIR('/dev/dsk',0,idirid,ierror)
call printdir(idirid,jdirent)
CALL PXFREWINDDIR(idirid,ierror)
call printdir(idirid,jdirent)
CALL PXFCLOSEDIR(idirid,ierror)
end

subroutine printdir(idirid,jdirent)
integer ierror, ilen, EEND
integer (KIND=8) jdirent, idirid
character*30 name

CALL PXFCONST('EEND',EEND,ierror)
   do while ((ierror .ne. EEND) .and. (ierror .eq. 0))
      CALL PXFREADDIR(idirid,jdirent,ierror)
      CALL PXFSTRGET(jdirent,'d_name',name,ilen,ierror)
         if (ierror .eq. 0) print *,name
   enddo
end

SEE ALSO

directory(3c)